我有這個路由集合:路由到有相同的名字,但不同參數的操作
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