MVC Preview 4 - No route in the route table matches the supplied values

邮差的信 提交于 2019-12-10 15:16:50

问题


I have a route that I am calling through a RedirectToRoute like this:

return this.RedirectToRoute("Super-SuperRoute", new { year = selectedYear });

I have also tried:

 return this.RedirectToRoute("Super-SuperRoute", new { controller = "Super", action = "SuperRoute", id = "RouteTopic", year = selectedYear });

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."?

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 :)


回答1:


What type is selectedYear? A DateTime? If so then you might need to convert to a string.



来源:https://stackoverflow.com/questions/5690/mvc-preview-4-no-route-in-the-route-table-matches-the-supplied-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!