问题
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