Including Pre-Compiled Views in an ASP.NET MVC Web

2019-04-10 01:31发布

问题:

Including Pre-Compiled Views in an ASP.NET MVC Web Application

Reference

please see above blog. am trying to create class library of user control in MVC 3. with reference to above blog i have created class library write view in it. but problem is how to register that view in my consumer application as partial view. PrecompiledMvcEngine is not found in nuget. which will register precompiled view in asp.net MVC application.

Give me an example how to do it?

回答1:

Basically you need to register a virtual path provider

  1. You must register a VirtualPathProvider in the Global.asax Application_Start handler.
  2. You must call the view in your DLL using the special path like so: return View("~/foldernameofdlllocation/nameofdll.dll/nameofview.cshtml");

To help track down the location of your view within the dll use something like reflector or telerik's JustDecopile (Free).

This blog post may be useful for you:

http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/

This Question may also be of use:

Using VirtualPathProvider to load ASP.NET MVC views from DLLs

Code Sample from blog post:

http://www.wynia.org/download/aspnetmvc-plugin-poc/POC.MVCPluginDemo.zip