4

Can anyone tell me how to follow a modular architecture and create MVC3 Razor views and controllers in a separate class library project?

enter image description here

I think it's a very common requirement for developing business applications. I checked the post of Plug-in architecture for ASP.NET MVC, but it doesn't work for MVC3 Razor views. The error message is confusing:"view is not found …or its master was not found or no view engine supports the searched locations. The following locations were searched: ….". I have no idea if the view/_ViewStart can be located. I also checked the post of A plugin framework with ASP.NET MVC3 and embedded Razor views, but it doesn't give any sample code.

The Umbraco CMS http://umbraco.codeplex.com/ implemented the plug-in architecture, but it's a too heavy framework to have in my project.

Can anyone give a small sample to show how to follow a modular architecture and create MVC3 Razor views and controllers in a separate class library project? Thx in adv.

Community
  • 1
  • 1
xoyoja
  • 436
  • 1
  • 5
  • 18
  • See my answer to this similar question: http://stackoverflow.com/questions/8939219/mvc-project-architecture-supporting-modules/8939242#8939242 – Jonas Høgh Mar 03 '12 at 13:30

1 Answers1

3

Have you tried using David Ebbos Razor Generator which allows you to precompile razor views in a separate project? The link is here. The website also includes a sample application.

Basically, this allows you to create the views in a separate project and then precompile them by setting the custom control of each view to point to the Razor Generator. The project also includes a pre-compiled view engine which will perform the search for the views in the other project for you.

Dangerous
  • 4,818
  • 3
  • 33
  • 48
  • I checked the post. The approach creates views and models in a separate class library project. But by module I mean having separate library which includes models views and controllers. The concept is similar with 'Area' or plugin architecture. A plugin here contains all elements, not only razor views. – xoyoja Mar 03 '12 at 15:04
  • The views are really the only tricky part to move to another class library. You can add controller classes to another library and specify the controller namespace for the ControllerBuilder. You can also easily move your models into another library. In this case your class project is the plugin and the main project can use reflections for any class projects that implement views/models/controllers. – Dangerous Mar 03 '12 at 16:20