ASP.NET MVC 母版页
在 findview 方法中的自定义视图引擎中,即使页面定义了母版页,母版名始终为空。 知道为什么,或者我怎样才能获得主名称?
在viewEngine类中:
MasterLocationFormats = new[] {
"~/{0}.master",
"~/Shared/{0}.master",
"~/Views/{1}/{0}.master",
"~/Views/Shared/{0}.master"
};
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { }
在页面中:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Empty.Master" Inherits="System.Web.Mvc.ViewPage" %>
主文件存在。
谢谢你!
In a custom viewengine in the findview method the mastername is always empty, even if the page has a masterpage defined.
Any idea why, or how can I get the mastername?
In the viewEngine class:
MasterLocationFormats = new[] {
"~/{0}.master",
"~/Shared/{0}.master",
"~/Views/{1}/{0}.master",
"~/Views/Shared/{0}.master"
};
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { }
In the page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Empty.Master" Inherits="System.Web.Mvc.ViewPage" %>
The master file exists.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您的主页不在标准位置?您可以发布一些自定义视图引擎的代码吗?
Maybe that your master page is not in standard location ? Can you post some code of your Custom viewengine ?
Debra,如果返回视图的操作方法特别提到了母版页名称(例如 return View("viewName", "masterName")),FindView 将尝试在 MasterLocationFormats 数组中指定的位置中查找它,并将其指定为视图的名称。母版页。该母版页将覆盖页面指令中指定的母版页。
另一方面,如果操作方法未指定母版页,FindView 将不会查找它,因为它不知道它。仅在渲染页面时,ViewEngine 才会从页面指令中获取母版页名称,并将其与页面的其余部分一起渲染。
希望有帮助。
Debra, if the action method which returns the View specifically mentions the masterpage name (e.g. return View("viewName", "masterName")), FindView will try to find it in the locations specified in the MasterLocationFormats array and assign it as the view's masterpage. This masterpage would override the masterpage specified in page directives.
If, on the other hand, masterpage is not specified by the action method, FindView will not look for it, either as it does not know about it. It is only at the time of rendering the page where ViewEngine picks up the master page name from page directives and renders it with the rest of the page.
Hope it helps.