混合WebForms和MVC:我应该做的母版? [英] Mixing WebForms and MVC: What should I do with the MasterPage?

查看:141
本文介绍了混合WebForms和MVC:我应该做的母版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始迁移的WebForms应用到MVC。这一过程将是渐进的,所以这两个系统必须共存。

I want to start migrating a WebForms App to MVC. The process will be gradual, so both systems must co-exist.

现在的问题是:我应该有两个MasterPages,一个用于WebForms的页面和其他的MVC的意见?有没有一种办法只有一个?

推荐答案

在ASP.NET MVC母版页应的 System.Web.Mvc.ViewMasterPage 而从的 System.Web.UI.MasterPage 。如果你的MVC使用后者,您将无法访问任何帮手。虽然你可以使用经典的web表单 ViewMasterPage ,因为它从母版导出(再次,您将无法访问帮手在Web窗体应用程序,但谁在乎呢)。

In ASP.NET MVC the master page should derive from System.Web.Mvc.ViewMasterPage while in classic WebForms from System.Web.UI.MasterPage. If in MVC you use the latter you won't have access to any helpers. Although you could use ViewMasterPage in classic webforms because it derives from MasterPage (once again you won't have access to helpers in the web forms application but who cares).

因此​​,要回答你的问题,是的,你可以有一个共同的母版页假设它从 ViewMasterPage 派生的。

So to answer your question, yes, you could have a common master page assuming it derives from ViewMasterPage.

这是说你可能不能够使这项工作作为一个MVC母版页,你会使用HTML佣工来呈现像 Html.RenderPartial 部分景色其中不会使在一个典型的WebForms应用经典的WebForms应用程序,反之亦然多大意义,你可能会使用一些服务器端控件像< ASP:XXX =服务器/> 或有一个格式标记(以 =服务器再次)与ViewState的污染,等等......几乎不使得MVC任何意义。所以,我的建议是不要做这样的。

This being said you probably won't be able to make this work as in an MVC master page you would use HTML helpers to render partial views like Html.RenderPartial which doesn't make much sense in a classic WebForms application and vice versa in a classic WebForms application you would probably be using some server side controls like <asp:xxx runat="server" /> or have a single form tag (again with runat="server") polluted with ViewState, etc... which hardly makes any sense in MVC. So my recommendation would be not to do like this.

这篇关于混合WebForms和MVC:我应该做的母版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆