我有单独的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