ASP.Net MVC 3 accessing CSS, JS files from separat

2019-03-22 06:24发布

I'm following this link, compile razor files into separate dll, and can get it to work except I can't figure out how to access JavaScript, CSS, and Images embedded in the dll.

Has anyone used this approach? It seems very promising. Thanks.

2条回答
Deceive 欺骗
2楼-- · 2019-03-22 06:34

The technique presented in this article is for embedding razor views into separate assemblies. It doesn't allow you to do so with static resources such as images, js and CSS. For those type of resources you will have to implement a custom solution. For example you could write a controller which, given a resource name, could read it from the assembly (GetManifestResourceStream) and write the stream to the response. Then you could simply generate links to this controller action in your views (Url.Action) and pass the resource name.

查看更多
Ridiculous、
3楼-- · 2019-03-22 06:37

You can use my EmbeddedResourceVirtualPathProvider which can be installed via Nuget to load all kinds of resources from referenced assemblies, and also can be set to take dependencies on the source files during development so you can update views without needing a recompile.

查看更多
登录 后发表回答