find a location for property in a new city

Tuesday, 8 June 2010

Use WebForms MasterPage in MVC project

Want to avoid having to duplicate your MasterPage design that you made in your ASP.NET WebForms project in you new MVC project? There is a simple way to share your master page across the ASP.NET web forms and MVC projects. Here's how:

Make a new "MVC 2 View Master Page" in your /Views/Shared folder and add the content:
<%@ Master Language="C#" MasterPageFile="~/MasterPages/Root.Master" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="RootTitle" runat="server">
    <asp:ContentPlaceHolder ID="RootTitle" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="RootContent" runat="server">
    <asp:ContentPlaceHolder ID="RootContent" runat="server"/>
</asp:Content>

Replace the URL with the destination of your web forms MasterPage and the ContentPlaceHolderIDs with the respective ones you used in your original web forms master page.

You can then go on to use your new MVC master page as you would before but it will inherit all the content from your web forms master page.

Note

Any form post controls on your web forms master page will not work on your MVC pages. I have found a way though which I explained in my post about making form posts work in a webform master page nested MVC page if that sort of thing interests you.

Follow britishdev on Twitter

8 comments:

  1. hhjjkkjjkkkkkkkkkkkkkk-+

    ReplyDelete
  2. i want use webforms like masterpage

    ReplyDelete
  3. what a well articulated comment

    ReplyDelete
  4. exellent solution.. it really helped me.. thanks

    ReplyDelete
  5. Informative post. I am happy to visit your blog. Thanks for sharing this post.
    electrical maintenance in chennai

    ReplyDelete
  6. Good article. This is very useful, Thanks for sharing this post.
    school websites design

    ReplyDelete
  7. Thank you for this great explanation. It was really helpful.

    3d rendering services

    ReplyDelete