Mixing WebForms and MVC: What should I do with the MasterPage?

无人久伴 提交于 2019-12-12 22:18:49

问题


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

The question is: Should I have two MasterPages, one for the WebForms pages and other for the MVC views? Is there a way to have only one?


回答1:


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

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

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.



来源:https://stackoverflow.com/questions/3578045/mixing-webforms-and-mvc-what-should-i-do-with-the-masterpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!