【问题标题】:The call is ambiguous between the following method or properties in ASP.NET MVC RenderActionASP.NET MVC RenderAction 中的以下方法或属性之间的调用不明确
【发布时间】:2011-04-10 20:33:48
【问题描述】:

在我安装 ASP.NET MVC 1.0 RTM 之前,调用一直正常。

Error: CS0121: The call is ambiguous between the following methods or properties

代码 sn-p

<%Html.RenderAction("ProductItemList", "Product"); %>

动作方法

public ActionResult ProductItemList()
{
  return View("~/Views/Product/ProductItemList.ascx", _repository.GetProductList().ToList());
}

【问题讨论】:

    标签: c# .net asp.net-mvc renderaction


    【解决方案1】:

    您有两个具有相同签名的操作方法,RenderAction 无法决定使用哪个。您需要以某种方式使操作变得独特。

    GETPOST 有一个动作时,我通常会看到这种情况,无论是没有参数还是参数。一个简单的解决方法是添加 FormCollection form 作为 POST 的参数。

    [HttpGet]
    public ActionResult ProductItemList()
    {
        //GET
    }
    
    [HttpPost]
    public ActionResult ProductItemList(FormCollection form)
    {
        //POST
    }
    

    【讨论】:

    • 我在同一个控制器中只有一种方法。但我解决了这个问题。对于 MVC RTM,RenderAction 语法与之前的不同。它是 (p => p.ProductItemList());%>
    • RTM?您使用的是哪个版本的 MVC。对于 2.0,您的语法会在 Product 控制器中查找 ProductItemList 操作。很高兴它为你工作。
    • RenderAction() 从调用它的视图中调用。 [HttpGet] 和 [HttpPost] 属性将用于来自实际 Http 请求的请求。 RenderAction 本质上被称为子请求(不是直接来自 Http)。
    • @Steve,完全明白。我把属性放在那里是为了澄清我对分离歧义方法的解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2012-02-09
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多