【发布时间】:2011-02-07 05:52:01
【问题描述】:
我有这组路线:
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
【问题讨论】:
标签: asp.net-mvc routing