Sharing views between ASP.NET MVC 3 Web applicatio

2019-03-20 19:20发布

问题:

I have several ASP.NET MVC 3 Web applications that have a lot of common objects:

  • The same login controller. The few differences between their login systems are captured in their web.config files.
  • Header/detail views: invoices, payment orders, payment orders, etc.

In order to make my code less redundant, I moved common controllers and views to a separate class library (models were already in their own class libraries). After googling for a while, I eventually found out how to call controllers in external assemblies, however, I still don't know how to call views in external assemblies. How do I do that?

回答1:

You may want to look at MVCContrib Portable areas. They allow you to compile an entire MVC application area into one assembly, including controllers, views and supporting files such as JavaScript and CSS. I've worked on a large project that made extensive use of them and they work well, especially combined with T4MVC.