Search code examples
asp.net-mvcasp.net-mvc-4razorrazor-2

How to override some razor views


ASP.NET & Mono MVC4 application uses Razor cshtml views from Views folders.

Application is deployed to number of sites.

In some customer sites customers want to override some views to add their spcific visual design. Using specific csss for this seems to be to sufficient.

How to allow to override some views

Customer specific views can be stored in database. How to force razor view engine to look to specific view override in database and use it if it exists ? If view is not found, standard one from cshtml file should used. Or is it possible to add come command to standard cshtml files which check and switch to specific view if it exists ?


Solution

  • You have to create your own virtual path provider and custom razor view engine ( Inherited from default one)

    Following link will help you on that.

    http://www.umbraworks.net/bl0g/rebuildall/2009/11/17/ASP_NET_MVC_and_virtual_views http://haacked.com/archive/2009/04/22/scripted-db-views.aspx/

    It is not related to Razor but it is surely be same.

    90% case custom virtual path provide will solve your problem.