Asp.net mvc MasterPageFile何时位于ASP.NET MVC WebForms ViewEngine中
何时检查视图/页面的MasterPageFile属性是否存在于ASP.NET MVC WebForms视图引擎中 我要做的是让以下代码不输出错误: 分析器错误消息:文件“/SomePlaceThatDoSenExist/Site.Master”不存在 在我的视图的.aspx文件中定义为:Asp.net mvc MasterPageFile何时位于ASP.NET MVC WebForms ViewEngine中,asp.net-mvc,master-pages,viewengine,Asp.net Mvc,Master Pages,Viewengine,何时检查视图/页面的MasterPageFile属性是否存在于ASP.NET MVC WebForms视图引擎中 我要做的是让以下代码不输出错误: 分析器错误消息:文件“/SomePlaceThatDoSenExist/Site.Master”不存在 在我的视图的.aspx文件中定义为: <%@ Page Language="C#" MasterPageFile="~/SomePlaceThatDosentExist/Site.Master" Inherits="System.Web.Mv
<%@ Page Language="C#" MasterPageFile="~/SomePlaceThatDosentExist/Site.Master" Inherits="System.Web.Mvc.ViewPage" >
并尝试了以下操作(在我的视图继承的自定义视图页面类中)
在这两种情况下,都会显示上面提到的错误
据我所知,OnPreInit是ViewPage生命周期中最早的一个点,那么是否有可能在生命周期中更早地使用它呢
在写和回答之前请注意:
- 我知道返回视图(“视图名”、“主页名”)李>
- 我知道动态母版页,但我想完成这个特定的任务
public CustomViewEngine()
{
MasterLocationFormats = new string[] {
"~/RealPlace/Site.Master""
};
}
如果要更改母版页的查找方式,可以实现自己的viewengine:
public CustomViewEngine()
{
MasterLocationFormats = new string[] {
"~/RealPlace/Site.Master""
};
}
解决此问题的最佳方法可能是创建一个自定义的解决此问题的最佳方法可能是创建一个自定义的该代码是否仅适用于返回视图(“ViewName”、“MasterPageName”);?如果.aspx文件已经声明了MasterPageFile@Page指令,那么这不会被忽略吗?是的,您必须使用View(“ViewName”、“MasterPageName”)。如果aspx没有自己的@Page指令,我就不是舒尔。我不想使用View(“ViewName”、“MasterPageName”),我想从View的@Page指令加载母版页。该代码不只是用于返回视图(“ViewName”、“MasterPageName”);吗;?如果.aspx文件已经声明了MasterPageFile@Page指令,那么这不会被忽略吗?是的,您必须使用View(“ViewName”、“MasterPageName”)。如果aspx不能有自己的@Page指令,我就不是舒尔。我不想使用View(“ViewName”、“MasterPageName”),我想从View的@Page指令加载母版页。谢谢你的帮助。我让我的虚拟路径提供程序在所有必要的可跨越方法(GetFile、FileExists、GetDirectory、DirectoryExists、CombineVirtualPath)中将任何出现的“SomePlace”替换为“RealPlace”,感谢这项工作。我让我的虚拟路径提供程序在所有必要的可跨越方法(GetFile、FileExists、GetDirectory、DirectoryExists、CombineVirtualPath)中用“RealPlace”替换任何出现的“SomePlace”
public CustomViewEngine()
{
MasterLocationFormats = new string[] {
"~/RealPlace/Site.Master""
};
}