ASP.NET MVC 母版页

发布于 2024-07-11 06:41:14 字数 48 浏览 7 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一向肩并 2024-07-18 06:41:14

大多数情况下,这取决于默认控件和继承。

AJAX Master和ASP.NET Master都继承自System.Web.UI.MasterPage,而MVC Master则继承自ViewMasterPage。

显然,这些为您提供了稍微不同的控制 - 正如John Clayton所述,ViewMasterPage 公开了 Ajax/Html/Url 帮助程序等,其他 MasterPage 无法使用这些帮助程序。

除此之外,默认控件略有不同:

  • ASP.NET 母版页将有默认的 Form 和两个 ContentPlaceHolder 控件(一个在头部,一个在表单中。AJAX
  • 母版页还在 Form 控件内添加了一个 ScriptManager 控件
  • 。MVC Master(取决于版本 - 我指的是 Beta)将只有两个 ContentPlaceHolder 控件(在 head 和 body 中)。

“生命周期差异”来自 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:

  • 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).

The "lifecycle differences" come from the Page/ViewPage, rather than the MasterPage/ViewMasterPage controls.

眼角的笑意。 2024-07-18 06:41:14

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...

友谊不毕业 2024-07-18 06:41:14

作为一个快速猜测,我不得不说答案是“生命周期”。 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文