1

我试图让 ViewEngine 使用额外的路径:

base.MasterLocationFormats = new string[] {
    "~/Views/AddedMaster.Master"
};

在 ViewEngine 的构造函数中。它适用于 aspx 和 ascx(PartialViewLocationFormats,ViewLocationFormats)。

我仍然需要在 web.config 或页面声明中提供 MasterPage。但如果我这样做了,则使用此声明,而不是 ViewEngine 中的声明。如果我使用空 MasterLocationFormats,则不会引发错误。这不是在 RC1 中实现的吗?

编辑:

使用:

return View("Index", "AddedMaster");

代替

return View("Index");

在控制器工作。

4

1 回答 1

1

您的示例并不完整,但我猜测您的代码块存在于类级别而不是构造函数方法内部。问题在于基类 ( WebFormViewEngine) 在构造函数中初始化了“位置格式”属性,因此覆盖了您的声明;

public CustomViewEngine()
{
    MasterLocationFormats = new string[] {
        "~/Views/AddedMaster.Master"
    };
}

如果您希望硬编码的 master 仅作为最后努力的默认值启动,您可以执行以下操作:

public CustomViewEngine()
{
    MasterLocationFormats = new List<string>(MasterLocationFormats) {
        "~/Views/AddedMaster.Master"
    }.ToArray();
}
于 2009-03-15T14:23:30.940 回答