3

I have an overloaded action in my Controller:

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

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

I'd like to use the same partial view for both lists but it will potentially have a differently 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 am getting the following error:
The current request for action 'AssignList' on controller type 'ImageController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult AssignList(Int32) on type UsiWeb.Controllers.ImageController System.Web.Mvc.ActionResult AssignList(Int32, Boolean) on type UsiWeb.Controllers.ImageController

How can I call the specific overload?

tereško
  • 58,060
  • 25
  • 98
  • 150
Jeff Martin
  • 10,812
  • 7
  • 48
  • 74

2 Answers2

4

Two options:

  • combine into a single method like:

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

  • Give a name to the overloaded method like:

    public ActionResult AssignList(int id){}

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

I will refer you to this SO link: Can you overload controller methods in ASP.NET MVC?

Community
  • 1
  • 1
Sunny
  • 6,286
  • 2
  • 25
  • 27
2

The easiest solution would be to combine the actions, making altList nullable:

public ActionResult AssignList(int id, bool? altList)
{
    ...
}
dahlbyk
  • 75,175
  • 8
  • 100
  • 122