开发者

ASP.net MVC 2 - Adding routes to external controllers

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" ro开发者_Python百科ute...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.


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" }
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜