问题
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