ASP.Net MVC 3 accessing CSS, JS files from separate DLL

Deadly 提交于 2020-01-01 03:39:36

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6702617/asp-net-mvc-3-accessing-css-js-files-from-separate-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!