我遇到了自定义 ViewEngine 的问题。我尝试覆盖 FindView 方法来设置主视图,而不必在每个视图页面中定义它。
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
if (string.IsNullOrEmpty(masterName))
{
masterName = this.MasterView;
}
return base.FindView(controllerContext, viewName, masterName, useCache);
}
从调试器的角度来看,一切看起来都很好:我没有在视图页面上设置属性 MasterPageFile,masterName 作为一个空字符串出现,masterName 被设置为 this.MasterView(通过初始化视图引擎来设置)。
问题是:浏览器显示“内容控件只允许在引用母版页的内容页中”。没有调试器出现。
有谁知道为什么或者这甚至是预期的行为?
提前致谢!