我有一些問題,重定向到一些行動基本上,如果我沒有參數路線或參數調用Id它工作正常,但是當我添加一些不同的參數路由RedirectToAction不起作用,它拋出錯誤:路由表中沒有路由與提供的值匹配。RedirectToAction參數在路線
[Route("First")]
public ActionResult First()
{
//THIS DOESN'T WORK
//return RedirectToAction("Second", new { area = "plans"});
//THIS WORKS
return RedirectToAction("Third", new { id = "12" });
}
[Route("Second/{area}")]
public ActionResult Second(string area)
{
return new ContentResult() { Content = "Second : " + area};
}
[Route("Third/{id}")]
public ActionResult Third(string id)
{
return new ContentResult() { Content = "Third " + id };
}
所以,當我輸入/首先它正確的重定向到第三,但到第二它拋出錯誤。
我沒有任何額外的東西在RouteConfig剛:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
你是對的!它適用於哪個areaName,但有沒有辦法將區域作爲參數?假設我們有Route(「{area}/Second」)以及如何重定向到不同的區域? – us3r 2015-02-05 14:07:11
同意。在路由站點中的任何區域時,ASP.NET MVC使用「{area}」。因此建議將該參數重命名以避免混淆。 – 2015-02-05 14:07:34