默认情况下,ASP.NET MVC 不支持重载方法。您必须使用不同的操作或可选参数。例如:
public ActionResult Create() {}
public ActionResult Create(string Skill, int ProductId) {}
public ActionResult Create(Skill Skill, Component Comp) {}
将更改为:
// [HttpGet] by default
public ActionResult Create() {}
[HttpPost]
public ActionResult Create(Skill skill, Component comp, string strSkill, int? productId) {
if(skill == null && comp == null
&& !string.IsNullOrWhiteSpace(strSkill) && productId.HasValue)
// do something...
else if(skill != null && comp != null
&& string.IsNullOrWhiteSpace(strSkill) && !productId.HasValue)
// do something else
else
// do the default action
}
OR:
// [HttpGet] by default
public ActionResult Create() {}
[HttpPost]
public ActionResult Create(string Skill, int ProductId) {}
[HttpPost]
public ActionResult CreateAnother(Skill Skill, Component Comp) {}
OR:
public ActionResult Create() {}
[ActionName("CreateById")]
public ActionResult Create(string Skill, int ProductId) {}
[ActionName("CreateByObj")]
public ActionResult Create(Skill Skill, Component Comp) {}
另请参阅此问答 https://stackoverflow.com/questions/7536119/mvc3-routing-with-overloaded-query-parameters/7536515#7536515