views:

45

answers:

1

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?

+3  A: 

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.

Darin Dimitrov
So, your recommendation is to have two MasterPages? (It's no big deal, since it do not change often)
Eduardo Molteni
Yes, this is my recommendation. There are cases where duplication is better rather than trying to much reuse and end up with a clone (the nature has created different species and trying to mix them could lead to unexpected results :-)).
Darin Dimitrov
Agree with you. Thanks!
Eduardo Molteni

related questions