开发者

MVC 3: May I place the controllers in a dll?

开发者 https://www.devze.com 2023-02-01 11:52 出处:网络
It really doe开发者_StackOverflowsn\'t matter, but there\'s a reason why I want the controllers in a DLL file.

It really doe开发者_StackOverflowsn't matter, but there's a reason why I want the controllers in a DLL file.

May I do that in an MVC project?


create a mvc project MvcApplication1.

create a mvc project MvcApplication2 and delete everything in it.

add reference to MvcApplication2 in MvcApplication1

create a HomeController inside MvcApplication2

create a view inside MvcApplication1

that's it.


Make sure to modify the routes in global.asax, like this:

public static void RegisterRoutes(RouteCollection routes) { 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
    routes.MapRoute( 
        name: "Default", 
        url: "{controller}/{action}/{id}",  
        defaults: new { 
            controller = "Home", 
            action = "Index", 
            id = UrlParameter.Optional 
        }, 
        namespaces: new[] {
            typeof(HomeController).Namespace 
        } 
    ); 
} 

Notice the additional namespaces argument to the MapRoute method.


Yes.

You don't have to do anything special.

0

精彩评论

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

关注公众号