How to separate model, view and controller in an ASP.NET MVC app into different assemblies

前端 未结 5 1215
一整个雨季
一整个雨季 2020-12-28 09:25

At the moment I am trying to get into the ASP.NET MVC framework.
For most of my test applications I used a single assembly/project. This worked fine for some smaller app

5条回答
  •  梦谈多话
    2020-12-28 09:41

    (unknown) is correct. Create two projects, a class library and an MVC web project. The MVC project should reference the class library that contains the controllers and code behind files (global asax etc). Here is an example layout.

    The class library should only contain .cs files and no views (.aspx/.ascx files).

    MyProject.BaseSite (class library)
        + Controllers
            - HomeController.cs
            - ... any other controllers
        - default.aspx.cs
        - global.asax.cs
    

    MVC web project should contain configs, views etc and a reference to your class library

    MyProject.ExampleSite
        + Content
            + scripts
            + css
            + images
        + Views
            + Home
                - index.aspx
                - .. other aspx files
            + Shared
                - Site.master
        - web.config
    

    Remember the different namespaces. You can then create multiple Example websites that reference the same code. This allows you to effectively skin your website completely differently.

提交回复
热议问题