我有这个路由集合:路由到有相同的名字,但不同参数的操作
routes.MapRoute(
"IssueType",
"issue/{type}",
new { controller = "Issue", action = "Index" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
这里是控制器类:
public class IssueController : Controller
{
public ActionResult Index()
{
// todo: redirect to concrete type
return View();
}
public ActionResult Index(string type)
{
return View();
}
}
为什么,当我要求http://host/issue我得到The current request for action 'Index' on controller type 'IssueController' is ambiguous between the following action methods:
我希望当没有参数时,第一种方法应该起作用,而当指定某个参数时,第二种方法应该起作用。
我犯了什么错误?
UPD:可能重复:Can you overload controller methods in ASP.NET MVC?
UPD 2:由于上面的链接 - 没有做出行动超载任何合法的方式,是吗?
UPD 3:动作方法不能被基于参数重载(c)中http://msdn.microsoft.com/en-us/library/system.web.mvc.controller%28VS.100%29.aspx
是的,很明显,但对这一问题 – zerkms 2010-04-13 03:14:59
是的没有实际的解决方案,这带来了一些有些超载但太脏,所以我选择重新命名第二种方法。谢谢 – zerkms 2010-04-13 05:17:23