14

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.

Schmalls
  • 1,434
  • 1
  • 19
  • 19
  • 1
    this means that you redirect to does not match any route in your route table, check your route table in `global.asax` file. my be you add paramters that does not declared in routes – Amir Ismail Sep 21 '11 at 17:50
  • Please provide more details about the `RedirectToAction` which is failing. Also, please provide the routes. – counsellorben Sep 21 '11 at 18:35

6 Answers6

23

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" });
Al Stevens
  • 499
  • 5
  • 6
  • This is the real answer... I ran into this issue using AttributeRouting, and even though it works on other pages without needing to specify the Area name, I had to do so for this particular Area. – jspinella Jan 11 '17 at 05:20
5

I had a similar problem once with RedirectToAction and found out that you need a valid route registered that leads to that action.

  • 6
    It did turn out to be something with the routes. It worked fine in MVC2 but I had to add an additional route with one less optional parameter to make it work with MVC3. – Schmalls Dec 14 '11 at 16:47
3

Check out glimpse and see if you can get some route debugging information: http://getglimpse.com/

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
1

You could add a route table to your RouteConfig.cs file like below:

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapMvcAttributeRoutes();

        var namespaces = new[] { typeof(HomeController).Namespace };

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute("name", "url", new { controller = "controllerName", action = "actionName" }, namespaces);
    }

NB: the "url" is what you'd type into the address bar say: localhost:/home

After setting up the route, use RedirectToRoute("url").

Or if you'd prefer the RedirectToAction() then you don't need to set up the above route, use the defaults. RedirectToAction(string action name, string controller name);

I hope this helps.

Nikki Punjabi
  • 383
  • 2
  • 16
0

There's a difference with trailing slashes in routes not working with MVC 3.0. MVC 2.0 doesn't have a problem with them. I.e., if you change the following:

"{controller}.mvc/{action}/{id}/"

to:

"{controller}.mvc/{action}/{id}"

it should fix this (from this thread, worked for me). Even when you use the upgrade wizard to move to MVC 3.0, this still throws InvalidOperationException. I'm not aware whether this is what Schmalls was talking about though.

Community
  • 1
  • 1
Abel
  • 56,041
  • 24
  • 146
  • 247
0

In my case, default route was missing:

routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
ErTR
  • 863
  • 1
  • 14
  • 37