MVC Preview 4-路由表中没有路由与提供的值匹配 [英] MVC Preview 4 - No route in the route table matches the supplied values
问题描述
我有一条通过RedirectToRoute调用的路由,如下所示:
I have a route that I am calling through a RedirectToRoute like this:
return this.RedirectToRoute("Super-SuperRoute", new { year = selectedYear });
我也尝试过:
return this.RedirectToRoute("Super-SuperRoute", new { controller = "Super", action = "SuperRoute", id = "RouteTopic", year = selectedYear });
global.asax中的路由如下:
The route in the global.asax is like this:
routes.MapRoute(
"Super-SuperRoute", // Route name
"Super.mvc/SuperRoute/{year}", // URL with parameters
new { controller = "Super", action = "SuperRoute", id = "RouteTopic" } // Parameter defaults
);
为什么我会收到错误消息:路由表中没有路由与提供的值匹配."
So why do I get the error: "No route in the route table matches the supplied values."?
我看到selectedYear的类型是var.当我尝试使用int.Parse转换为int时,我意识到selectedYear实际上为null,这可以解释问题.我想下一次我将在断点处更加关注变量的值:)
I saw that the type of selectedYear was var. When I tried to convert to int with int.Parse I realised that selectedYear was actually null, which would explain the problems. I guess next time I'll pay more attention to the values of the variables at a breakpoint :)
推荐答案
选择哪种类型年份?日期时间?如果是这样,那么您可能需要转换为字符串.
What type is selectedYear? A DateTime? If so then you might need to convert to a string.
这篇关于MVC Preview 4-路由表中没有路由与提供的值匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!