Load views from location outside the mvc website

不想你离开。 提交于 2019-12-08 10:06:59

问题


I'm trying to load an MVC view form a folder outside the location of the app.

My app is in C:\dev\myproject\ and the view file i'm trying to load is located in D:\viewsfolder\something is it possible to do that?

I tried passing an absolute path to the return View() method but that didn't work.


回答1:


This is not supported by standard ASP.NET MVC. You may take a look at the RazorEngine plugin which allows you to render a Razor view from a string.

You haven't really explained why you need to do that by the way. Maybe there's a better approach to your particular problem.




回答2:


The best way to do this is to have your Views Precompiled into a dll which can be used across multiple locations with only one code base.

This can be done using the Razor Generator Plugin which you can find here:

http://razorgenerator.codeplex.com/



来源:https://stackoverflow.com/questions/17135325/load-views-from-location-outside-the-mvc-website

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