Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RedirectToAction Causes "No route in the route table matches the supplied values" in ASP.NET MVC 3

I have a project that I recently upgraded to ASP.NET MVC 3. On my local machine, everything works fine. When I deploy to the server, I get an error anytime I use a RedirectToAction call. It throws a System.InvalidOperationException with the error message No route in the route table matches the supplied values. My assumption is that there is some configuration problem on the server, but I can't seem to be able to figure it out.

like image 609
Schmalls Avatar asked Sep 21 '11 17:09

Schmalls


People also ask

What does RedirectToAction do in MVC?

RedirectToAction(String, String, Object)Redirects to the specified action using the action name, controller name, and route dictionary.

What is the difference between RedirectToAction () and RedirectToRoute () in MVC?

RedirectToAction will return a http 302 response to the browser and then browser will make GET request to specified action. Save this answer. Show activity on this post. Ideally I would use RedirectToRoute for Action Links/Images and RedirectToAction in Controller's Action to redirect to another Controller's Action .

What is difference between redirect and RedirectToAction?

RedirectToAction is meant for doing 302 redirects within your application and gives you an easier way to work with your route table. Redirect is meant for doing 302 redirects to everything else, specifically external URLs, but you can still redirect within your application, you just have to construct the URLs yourself.

What is route value in MVC?

RouteData is a property of the base Controller class, so RouteData can be accessed in any controller. RouteData contains route information of a current request. You can get the controller, action or parameter information using RouteData as shown below.


1 Answers

I ran into this with areas within MVC3 when redirecting across areas. As others have said, Glimpse is very useful here.

The solution for me was to pass in the Area within the route values parameter changing:

return RedirectToAction("ActionName", "ControllerName");

to:

return RedirectToAction("ActionName", "ControllerName", new { area = "AreaName" });
like image 122
Al Stevens Avatar answered Oct 06 '22 00:10

Al Stevens