Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use web form master page as master page for ASP.Net MVC views programatically

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.

like image 739
Amir Ismail Avatar asked Dec 19 '11 16:12

Amir Ismail


People also ask

Can we use master page in MVC?

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.

Which events can be used to programmatically set the master page file for an ASP.NET page?

To set the master page programmatically, then, we can either create an event handler for the PreInit event or override the OnPreInit method.


1 Answers

Look at this articles to get an overview about mixing Webforms with MVC:

  • Mixing Razor Views and WebForms Master Pages with ASP.NET MVC 3
  • Using Razor Pages with WebForms Master Pages

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.

like image 160
Jan Avatar answered Sep 27 '22 18:09

Jan