【发布时间】:2019-06-19 00:33:47
【问题描述】:
我正在尝试重定向到 RecomController 中的路由并且操作是索引,我已经在我的 RouteConfig 文件中定义了路径,并且还指定了我在调用我的 RedirectToRoute 函数时传递的 id 参数。由于某种原因,它找不到该路径。
我还在 RecomController Index 操作上方创建了一个 Route 属性,但它仍然无法将我导航到该路径。我错过了什么吗?
RouteConfig.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Recomroute",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Recom", action = "Index", id = UrlParameter.Optional }
);
}
RecomController.cs:
[Route("Recom/Index")]
public ActionResult Index(int id)
{
............//Functioning
}
调用函数(在另一个控制器中):
ProjectController.cs:
return RedirectToRoute("Recom/Index/{id}", new {id = projectdto.Id });
【问题讨论】:
-
关于您的路线顺序,您应该寻找这个问题:stackoverflow.com/questions/35661062/…。
标签: asp.net asp.net-mvc asp.net-mvc-4