I have a controller with 3 overloads for a create method:
public ActionResult Create() {}
public ActionResult Create(string Skill, int ProductId) {}
public ActionResult Create(Skill Skill, Component Comp) {}
in one of my views I want to create this thing so I call it like this:
<div id="X">
@Html.Action("Create")
</div>
but I get the error:
{“The current request for action ‘Create’ on controller type
‘XController’ is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Create() on type
X.Web.Controllers.XController System.Web.Mvc.ActionResult
Create(System.String, Int32) on type X.Web.Controllers.XController
System.Web.Mvc.ActionResult Create(X.Web.Models.Skill,
X.Web.Models.Component) on type X.Web.Controllers.XController”}
but since the @html.Action() is passing no parameters, the first overload should be used. It doesn’t seem ambiguous to me (which only means I don’t think like a c# compiler).
can anyone point out the error of my ways?
By default, overloading methods is not supported in ASP.NET MVC. You have to use difference actions or optional parameters. For example:
will changes to:
OR:
OR:
See also this Q&A