ASP.NET MVC 母版页
ASP.NET 母版页和 MVC 母版页有什么区别? 那么 AJAX 母版页呢?
What's the difference between the ASP.NET Master Page, and the MVC Master Page? And the AJAX Master Page for that matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数情况下,这取决于默认控件和继承。
AJAX Master和ASP.NET Master都继承自System.Web.UI.MasterPage,而MVC Master则继承自ViewMasterPage。
显然,这些为您提供了稍微不同的控制 - 正如John Clayton所述,ViewMasterPage 公开了 Ajax/Html/Url 帮助程序等,其他 MasterPage 无法使用这些帮助程序。
除此之外,默认控件略有不同:
“生命周期差异”来自 Page/ViewPage,而不是 MasterPage/ViewMasterPage 控件。
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.
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.
Other than that, the default controls are slightly different:
The "lifecycle differences" come from the Page/ViewPage, rather than the MasterPage/ViewMasterPage controls.
MVC 中的 ViewMasterPage 只不过是一个母版页,它公开与 ViewPage 相同的帮助程序。 这使您可以访问 AjaxHelper、HtmlHelper、TempDataDictionary、UrlHelper、ViewContext、ViewData 和 HtmlTextWriter。
与 ViewPage 一样,当您使用 WebFormsViewEngine(默认)时,您应该不惜一切代价抵制任何超载页面生命周期事件的冲动! 它们仍然在那里,并且仍然会运行,因为在页面上仍然会调用 ProcessRequest(...) 。
您指的是哪个 AJAX 母版页? 我不熟悉框架中包含的任何内容......
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.
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.
Which AJAX master page are you referring to? I'm not familiar with any included with the framework...
作为一个快速猜测,我不得不说答案是“生命周期”。 ASP.NET WebForms、MVC 和 AJAX 都有不同的生命周期,这会影响母版页控件需要响应的事件。 WebForms 母版页需要响应 Load、DataBind、PreRender、Render 等。MVC 母版页可能(对此不确定)只需要 Render 操作。 所有其他事件都是多余的,等效的代码可以在控制器中找到。 最后,AJAX 母版页需要在正常请求之上处理 AJAX 请求。
正如我所说,这只是一个猜测,因此建议进行更多研究
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.
As I said, this is a bit of a guess so more research is recommended