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

后端 未结 6 1259
春和景丽
春和景丽 2021-02-19 08:41

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 Redirec

6条回答
  •  既然无缘
    2021-02-19 09:15

    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.

提交回复
热议问题