We have a running solution contains many web forms
application with the same master page, we created a class library project for master page and its controls and reference it as a dll
inside each web form application and assign master page programatically
Now we will add two new application to our solution but we decided to use ASP.Net MVC 3
for building these new applications.
The problem is, we must use the same master page for the new applications, so how can we set the master page for our views using code?
Take care to remember our master page is a class library project.
You add a new view master page to an MVC project by right-clicking the Views\Shared folder, selecting the menu option Add, New Item, and selecting the MVC View Master Page template (see Figure 1). You can create more than one view master page in an application.
To set the master page programmatically, then, we can either create an event handler for the PreInit event or override the OnPreInit method.
Look at this articles to get an overview about mixing Webforms with MVC:
Another interesting project is Zeus when it comes to a mixed Webforms/MVC solution. It contains helpers to use HtmlHelper and UrlHelper on Webform pages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With