0
我有两个使用相同视图的asp.net MVC 3 web项目,我想将这些视图放在一个包含常见项目的Web项目中控制器,actionfilters,扩展方法等等(这两个项目上方的项目文件夹)。Asp.net定制剃须刀视图引擎开箱即用访问视图
我创建了这个自定义视图引擎,修改视图和局部视图,位置。
public class GenericViewEngine : RazorViewEngine
{
public GenericViewEngine(): this(null)
{ }
public GenericViewEngine(IViewPageActivator viewPageActivator)
{
base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/../Framework.Web/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/../Framework.Web/Views/Shared/{0}.cshtml" };
base.MasterLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/../Framework.Web/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/../Framework.Web/Views/Shared/{0}.cshtml" };
base.PartialViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/../Framework.Web/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/../Framework.Web/Views/Shared/{0}.cshtml" };
base.FileExtensions = new string[] { "cshtml" };
}
protected override IView CreatePartialView (ControllerContext controllerContext, string partialPath)
{
return base.CreatePartialView(controllerContext, partialPath);
}
protected override IView CreateView (ControllerContext controllerContext, string viewPath, string masterPath)
{
return base.CreateView(controllerContext, viewPath, masterPath);
}
}
我得到一个异常,说:不能使用领先..退出顶部目录以上。
我怎么能把这两个项目的共同意见从每个web项目中拿出来?有没有解决方案可以避免将视图编译成主要的通用Web项目?
在此先感谢。
何塞。