asp.net-mvc ASP.NET MVC 母版页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/452698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET MVC Master Pages
提问by Ash
What's the difference between the ASP.NET Master Page, and the MVC Master Page? And the AJAX Master Page for that matter?
ASP.NET 母版页和 MVC 母版页有什么区别?和 AJAX 母版页呢?
采纳答案by Zhaph - Ben Duguid
Mostly it comes down to the default controls and inheritance.
主要归结为默认控件和继承。
The AJAX Master and ASP.NET Master both inherit from System.Web.UI.MasterPage, while the MVC Master inherits from ViewMasterPage.
AJAX Master 和 ASP.NET Master 都继承自 System.Web.UI.MasterPage,而 MVC Master 继承自 ViewMasterPage。
Obviously, these give you slightly different controls on this - as stated by John Clayton, the ViewMasterPage exposes the Ajax/Html/Url helpers and the like, which are not available to the other MasterPages.
显然,这些为您提供了稍微不同的控制 - 正如John Clayton所述,ViewMasterPage 公开了 Ajax/Html/Url 助手等,其他 MasterPage 无法使用这些帮助程序。
Other than that, the default controls are slightly different:
除此之外,默认控件略有不同:
- ASP.NET Master page will have the default Form and two ContentPlaceHolder controls (one in the head, one in the form.
- AJAX Master page also adds a ScriptManager control inside the Form control.
- MVC Master (depending on version - I'm refering to the Beta) will just have two ContentPlaceHolder controls (in head and body).
- ASP.NET 母版页将具有默认的 Form 和两个 ContentPlaceHolder 控件(一个在头部,一个在表单中。
- AJAX 母版页还在 Form 控件内添加了一个 ScriptManager 控件。
- MVC Master(取决于版本 - 我指的是 Beta)将只有两个 ContentPlaceHolder 控件(在头部和主体中)。
The "lifecycle differences" come from the Page/ViewPage, rather than the MasterPage/ViewMasterPage controls.
“生命周期差异”来自 Page/ViewPage,而不是 MasterPage/ViewMasterPage 控件。
回答by John Clayton
The ViewMasterPage in MVC is little more than a master page that exposes the same helpers as the ViewPage. This gives you access to the AjaxHelper, HtmlHelper, TempDataDictionary, UrlHelper, ViewContext, ViewData, and the HtmlTextWriter.
MVC 中的 ViewMasterPage 只不过是一个母版页,它公开与 ViewPage 相同的帮助程序。这使您可以访问 AjaxHelper、HtmlHelper、TempDataDictionary、UrlHelper、ViewContext、ViewData 和 HtmlTextWriter。
Like the ViewPage, when you are using the WebFormsViewEngine (default), you should resist any urge to overload page lifecycle events at all costs! They are still there, and they will still run since under the hood ProcessRequest(...) is still called on the page.
与 ViewPage 一样,当您使用 WebFormsViewEngine(默认)时,您应该不惜一切代价抵制任何重载页面生命周期事件的冲动!它们仍然存在,并且它们仍然会运行,因为在后台 ProcessRequest(...) 仍然在页面上被调用。
Which AJAX master page are you referring to? I'm not familiar with any included with the framework...
您指的是哪个 AJAX 母版页?我不熟悉框架中包含的任何内容......
回答by Mike Minutillo
As a quick guess I'd have to say that the answer would be "lifecycle". ASP.NET WebForms, MVC and AJAX all have different lifecycles which would effect the events which need to be responded to by a master page control. A WebForms Master Page would need to respond to Load, DataBind, PreRender, Render, etc. An MVC Master Page would probably (not sure on this) only need the Render action. All the other events are superfluous and the equivalent code would be found in the controller. Lastly, the AJAX Master Page would need to handle AJAX requests on top of normal ones.
作为一个快速的猜测,我不得不说答案是“生命周期”。ASP.NET WebForms、MVC 和 AJAX 都有不同的生命周期,这会影响需要由母版页控件响应的事件。WebForms Master Page 需要响应 Load、DataBind、PreRender、Render 等。MVC Master Page 可能(不确定)只需要 Render 操作。所有其他事件都是多余的,可以在控制器中找到等效的代码。最后,AJAX 母版页需要在普通请求之上处理 AJAX 请求。
As I said, this is a bit of a guess so more research is recommended
正如我所说,这有点猜测,因此建议进行更多研究

