2

REQUIREMENT

I have a project and one of requirements is load external small websites like plugins. This websites must accomplish few requirements of course (like mvc and net version and other more to make it compatible).

This plugins must be allocated in a new folder inside my MVC Website. And in it there are Views folder and compiled website dll result (controllers, models,...)

CURRENT DEVELOPMENT

I implementented a custom ViewEngine to load Views from this folder, and a ControllerFactory that makes the trick for controllers that are not located in my main website.

I based my code in http://christianjvella.com/wordpress/mef-mvc-defining-controllerfactory/ for ControllerFactory and Can I specify a custom location to "search for views" in ASP.NET MVC? for ViewEngines

PROBLEM

All seems to works well with a simple html view. But when I use some MVC helpers or objects like ViewBag, @Url.Content, @Html.DropDownList i have an error that the object is null or not exist.

Overriding CreateView method in ViewEngine, it returns an IView instance correctly and controllerContext have ViewBag and other necessary features.

It seems that, at the moment of view rendering, MVC doesn't attach controllerContext to view instance...

Is this a limitation of MVC that don't pass controllerContext to external loaded views or externals controllers? Any idea or workaround?

Community
  • 1
  • 1
David Peláez
  • 23
  • 1
  • 4

3 Answers3

2

Your views have to be pre-compiled. You can use precompiled MVC views for doing so. Precompiled views are created using a VS Addin called as RazorGenerator.

You can read more about here, below example puts Views in separate class library! ,some thing that you are looking for:

http://www.c-sharpcorner.com/UploadFile/97fc7a/article-precompiled-razor-view-using-razorgenerator-mvc-and/

Ajay Kelkar
  • 4,591
  • 4
  • 30
  • 29
0

Well, I forget to include web.config in plugins Views folder, with it works fine because it defines Razor and MVC dll references.

Thanks for all

David Peláez
  • 23
  • 1
  • 4
  • Could you elaborate on this a bit more,e.g. provide a few more details? There is nothing wrong with providing a complete and detailed answer to your own question. I'd love to upvote this answer. – Manfred Apr 11 '18 at 00:10
0

You could also use a VirtualPathProvider to serve things from other assemblies, including static assets and views. This way you can use the standard ViewENgine

https://www.nuget.org/packages/EmbeddedResourceVirtualPathProvider/

mcintyre321
  • 12,996
  • 8
  • 66
  • 103