RedirectToAction method calls to controller in shared library

Oct 2, 2014 at 5:06 PM
Edited Oct 2, 2014 at 5:07 PM
Hey Max. From some of my earlier posts you saw that I keep shared controllers in a separate project that gets referenced from various MVC web apps.

I would like to be able to redirect certain incoming requests from the MVC controller to be handled by the shared controller instead. I assume RedirectToAction is the proper method to do this? However I am unsure of the parms to be passed. Everything I have tried so far fails with an error "No route in the route table matches the supplied values. ".

Here is the routes.axd output for the controller action I am trying to pass into RedirectToAction...
routes.MapRoute(null, "shared/controller/application", 
    new { controller = "Controller", action = "Application" }, 
    new[] { "SharedProject.Controllers.Shared" });
Thanks in advance,
Wade
Coordinator
Oct 2, 2014 at 5:23 PM
When you register the shared controllers, are you using a base route?
Oct 2, 2014 at 5:29 PM
Yes, I actually register two base route.
1) DefaultController is in the MVC web app
            routes.MapCodeRoutes(
                rootController: typeof(DefaultController)
                , settings: new CodeRoutingSettings { 
                    EnableEmbeddedViews = true
                    , RouteFormatter = args => args.OriginalSegment.ToLowerInvariant()
                }
            );
2) DirectoryController is at the root of the SharedProject controllers folder
            routes.MapCodeRoutes(
                rootController: typeof(SharedProject.Controllers.DirectoryController)
                , settings: new CodeRoutingSettings {
                    EnableEmbeddedViews = true
                    , RouteFormatter = args => args.OriginalSegment.ToLowerInvariant()
                }
            );
Coordinator
Oct 2, 2014 at 5:38 PM
The code you are showing me is not using base route.

I think this should work:
return RedirectToAction("Application", "~~Shared.Controller");
Marked as answer by maxtoroq on 10/2/2014 at 10:49 AM
Oct 2, 2014 at 5:47 PM
Ok, I guess I don't understand what a base route is. Nevertheless what you sent me works so I am good to go... Thanks!
Coordinator
Oct 2, 2014 at 5:50 PM
The MapCodeRoutes method has an overload with three parameters, the first one is the base route.