MVC3 Separation of multiple views to common a model-controller?
I have got an MVC3/Razor/C# project that I want to separate and just looking for tips开发者_开发问答 on this.
For example, a few websites will have different front-end (view) but share the same model and controller.
In theory, I should be able to create several simple view projects, that point to a common Controller and Model project.
Anything I should watch out for in this approach, and is this the recommended way?
Thanks.
Anything I should watch out for in this approach, and is this the recommended way?
It's a good approach but it will depend on your requirements. For example if you have similar models and controllers you could place them in a separate assembly and then reuse this assembly in different ASP.NET MVC projects where you would only tweak the views based on the specific requirements of the given project. Be careful though. If there are conceptual differences in those sites (not only static text, CSS and colors) this means that the view models will not be the same, so you probably shouldn't try to reuse too much or you will endup with soup of if
and switch
statements in your controllers and act differently according to the site. If this happens, it means that you shouldn't have tried to reuse your controllers and view models. As far as the domain models and service layer is concerned, then you absolutely should reuse it.
精彩评论