【问题标题】:Why are these 2 methods ambiguous为什么这两种方法模棱两可
【发布时间】:2014-12-20 18:18:44
【问题描述】:

我收到一个关于我的函数不明确的错误

当前对控制器类型的操作“索引”请求 'ProductController' 在以下操作方法之间不明确: System.Web.Mvc.ActionResult Index(bconn.ui.Models.Vm, Int32, Int32) on 键入 bconn.ui.Controllers.ProductController System.Web.Mvc.ActionResult Index(System.String, System.String) on 输入 bconn.ui.Controllers.ProductController

如您所见,一个控制器具有以下签名

public ActionResult Index(Vm model, int startIndex, int pageSize)

还有一个

public ActionResult Index(string selected, string nothing)

由于一个有int 值,这些值不能为空,我看不出这里有什么歧义?

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    这和普通班不同。当你有action方法时,你不能重载它们,除非你使用[HttpGet][HttpPost]属性来区分它们。

    例如,您需要:

    [HttpGet]
    public ActionResult Index(Vm model, int startIndex, int pageSize) 
    {
        ...
    }
    

    [HttpPost]
    public ActionResult Index(string selected, string nothing)
    {
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      相关资源
      最近更新 更多