Reputation: 3883
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.
Upvotes: 9
Views: 4834
Reputation: 1404
Amir, I uploaded a working sample at here. Steps,
1) Downloaded and converted a sample application from here.
2) Add a MVC 3 application in this solution and Add reference the class library of above solution.
3) Specify the MasterPage in MVC view(either in view, MasterPageFile="~/MasterPageDir/MasterPage.master"
or in controller return View("Index",masterName: MasterPageVirtualPathProvider.MasterPageFileLocation);
).
4) Put these lines in global.asax.
MasterPageVirtualPathProvider vpp = new MasterPageVirtualPathProvider();
HostingEnvironment.RegisterVirtualPathProvider(vpp);
Upvotes: 1
Reputation: 28208
If you really want to go the MVC route moving forward then you should probably invest some time to convert your master page to a layout. Everything else would be a hack/workaround.
Upvotes: 1
Reputation: 16038
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.
Upvotes: 3