Nesting Razor Views in a Class Library as Resources

I use VirtualPathProvider to provide thematic views.

In the action method, I want to return the view along the way

return View("~/Themes/SomeTheme.dll/Views/Content/Item.cshtml");

In Visual Studio Item.cshtml there is an "Embedded Resource" assembly action.
VirtualPathProvider finds this .cshtml file, but I get an error

The view at '~/Themes/SomeTheme.dll/Views/Content/Item.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.

I assume I need to compile this view, and I followed these instructions .

Now VirtualPathProvider cannot find Item.cshtml as it is no longer an embedded resource.

How to solve this problem? I can not add a link to this SomeTheme.dll because the activated theme loads dynamically when the application starts.

I did this before with aspx files, and they did not need to be compiled. They worked out of the box as embedded resources.

+3
source share
3 answers

I ran into a similar issue with aspx inline views. The compilation that occurs when viewing the page depends on some parameters in the web.config file in the views folder. Nested resources are not in the views folder, so do not use these settings and do not compile.

+2
source

Try install-package EmbeddedResourceVirtualPathProvider

+1
source

intellisense View. , web.config.

<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />        

, @Inherits System.Web.Mvc.WebViewPage ( , ), .

0

Source: https://habr.com/ru/post/1783884/


All Articles