我有單獨的dll與控制器和視圖(與通常的文件夾結構)。這裏是我的自定義視圖引擎:自定義RazorViewEngine無法正常工作
public class SettingsViewEngine : RazorViewEngine
{
public SettingsViewEngine()
{
//if I commit this nothing changes
MasterLocationFormats = new[]
{
"~/bin/Views/{1}/{0}.cshtml",
"~/bin/Views/Shared/{0}.cshtml"
};
ViewLocationFormats = new[]
{
"~/bin/Views/{1}/{0}.cshtml", //if I commit this line it starts look at
//at shared folder.Looks like only first
//line of ViewLocationFormats array used always.
"~/bin/Views/Shared/{0}.cshtml"
};
}
}
- 視圖被複制到bin文件夾。沒有佈局屬性一切正常。但是當它被設置我得到錯誤它不能被發現在
"~/bin/Views/MyLayout.cshtml"
任何想法?謝謝。
更新
我有更新我的旁邊ovveride搜索引擎:
protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
{
// "~/bin/Views/Shared/_SettingsManagerLayout.cshtml" works (able find)
return base.CreateView(controllerContext, viewPath, masterPath);
}
調試時,我能夠看到,主空string.If我通過路徑直接我得到了奇怪的錯誤from layout -
System.Web.WebPages.Html.HtmlHelper'不包含'ActionLink'的定義和最佳擴展方法重載
System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper,字符串,字符串對象)」具有一些無效參數
這裏是如何看我的看法:
@inherits System.Web.Mvc.WebViewPage
@{
Layout="_SettingsManagerLayout.cshtml";
}
...
更新
的幾點思考:我有錯誤 -
佈局頁「_SettingsManagerLayout.cshtml」無法在以下路徑找到:「〜/斌/瀏覽/設置/ _SettingsManagerLayout.cshtml」
但我希望視圖引擎將檢查指定的幾個路徑在MasterLocationFormats(ViewLocationFormats)中,這是通過具有相同視圖引擎的根項目爲控制器視圖完成的。
結束診斷
自定義視圖引擎忽略來自ViewLocationFormats MasterLocationFormats和僅使用第一項。
你是如何設置的佈局_ViewStart.cshtml文件?像'Layout =「〜/ bin/Views/Shared/_Layout.cshtml」;'? –
沒有。無bin前綴。 – tony