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項目?
在此先感謝。
何塞。