views:

28

answers:

1

Is it possible to add routes to controllers defined in external assemblies? Everything I've seen so far doesn't seem to allow for it.

Based on the below help

I've added the following two routes as a test and no matter what I do it keeps defaulting to the "Default" route...however if I change the name of the "Browse" controller to the name of another controller in my class it works fine.

    routes.MapRoute(
        "Browse",
        "browse/{controller}/{action}/{id}",
        New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional},
        New String() {"MySite.Browse.Controllers"})

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional},
        New String() {"MySite.Controllers"})

Any thoughts?

Seems the above might be MVC 1 only as it doesn't actually call the BrowseController in my external assembly.

+1  A: 

This particular site might help: http://dotnet.dzone.com/news/how-call-controllers-external-

The clip of it is posted here for discussion

Route externalBlogRoute = new Route(
    "blog/{controller}/{action}/{id}",
    new MvcRouteHandler()
);

externalBlogRoute.DataTokens = new RouteValueDictionary(
    new {
         namespaces = new[] { "ExternalAssembly.Controllers" }
    });

routes.Add("BlogRoute", externalBlogRoute);


routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" },
    new[] { "ExternalAssembly.Controllers" }
);
MyNameIsJob
Thanks, it works fine when the controllers have different names but it appears to default to not work when they have the same name. I've checked the page and they say it's supposed to work...
BuildStarted
It's not that big of a deal, I guess, to have different controller names in each assembly...just hoping it wouldn't be an issue. :)
BuildStarted
Hmm, I guess I spoke too soon. I didn't notice it wasn't calling the BrowseController as I didn't put an obvious differentiation in the View...back to square one. Based on the age of that link I'll say it's probably MVC 1 only.
BuildStarted
Too tired, it works just fine - I forgot to copy the views. Thanks, MyNameIsJob
BuildStarted
Glad it worked out for you.
MyNameIsJob