How can I trigger an overloaded action in .net mvc?

I have an overloaded action in my controller:

    public ActionResult AssignList(int id)
    {
        ...
    }

    [AcceptVerbs((HttpVerbs.Get))]
    public ActionResult AssignList(int id, bool altList)
    {
        ...
    }

I would like to use the same partial view for both lists, but it will potentially have a great filtered list of images.

I am trying to call it from another view using RenderAction:

<% Html.RenderAction("AssignList", "Image", new { id = Model.PotholeId, altList = true }); %>

However, I get the following error: The
current request for the "AssignList" action on the type of the "ImageController" controller is ambiguous between the following action methods: System.Web.Mvc.ActionResult AssignList (Int32) of the type UsiWeb.Controllers.ImageController System.Web.Mvc.ActionResult AssignList (Int32, Boolean) by type UsiWeb.Controllers.ImageController

How can I cause a specific overload?

+3
2

:

  • , :

    public ActionResult AssignList (int id, bool? altList) {}

  • , :

    public ActionResult AssignList (int id) {} ​​

    [ActionName ( "SomeActionName" )] public ActionResult AssignList (int id, bool altList) {}

SO: ASP.NET MVC?

+4

- , altList nullable:

public ActionResult AssignList(int id, bool? altList)
{
    ...
}
+2

Source: https://habr.com/ru/post/1739704/


All Articles