Mat*_*ell 4 asp.net-mvc asp.net-mvc-routing
我有一个我通过RedirectToRoute调用的路由,如下所示:
return this.RedirectToRoute("Super-SuperRoute", new { year = selectedYear });
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
return this.RedirectToRoute("Super-SuperRoute", new { controller = "Super", action = "SuperRoute", id = "RouteTopic", year = selectedYear });
Run Code Online (Sandbox Code Playgroud)
global.asax中的路由是这样的:
routes.MapRoute(
"Super-SuperRoute", // Route name
"Super.mvc/SuperRoute/{year}", // URL with parameters
new { controller = "Super", action = "SuperRoute", id = "RouteTopic" } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
那么为什么我会收到错误:"路由表中没有路由与提供的值匹配."?
我看到selectedYear的类型是var.当我尝试使用int.Parse转换为int时,我意识到selectedYear实际上是null,这可以解释问题.我想下次我会更加注意断点处变量的值:)
| 归档时间: |
|
| 查看次数: |
2909 次 |
| 最近记录: |