skip to main | skip to sidebar

Sunday, May 18, 2008

Nested Master Pages with the MVC Framework

If you install the MVC Framework CTP2 you may notice that it doesn't come with a nested master page template, but don't worry it very easy to create your own from the existing Web Forms template. Here's how:

First add a standard (web forms) nested master page:

AddDialogue

Next, in the code behind file 'myNested.master.cs' inherit from System.Web.Mvc.ViewMasterPage:

CodeBehind

Then you are ready to go, just add a content placeholder:

markup

Posted by Mike Hadlow at 8:26 am
Labels:

7 comments:

Anonymous said...

following your instruction but i cannot get it work. I inherit the nested masterpage from system.web.mvc.viewmasterpage, in the code behind, but i can not do Html.ActionLink on the html part of the master page.

1:50 am
Mike Hadlow said...

Hi Anonymous,

Check out the master pages in the Suteki Shop code (my open source eCommerce application), to see how it's done.

8:26 am
Mr. Bluesummers said...

Yah, same here. I tried creating a nested master page (with codebehind like yours), but I'm getting parser errors:

The type 'System.Web.Mvc.ViewMasterPage' is ambiguous: it could come from assembly [my project] or from assembly [System.Web.Mvc].

7:41 am
Mr. Bluesummers said...

In fact, after downloading your code, your nested master pages are subject to the same error that Anonymous described- the HTML helper isn't found.

7:44 am
Mr. Bluesummers said...
This comment has been removed by the author.
8:47 am
Andy said...

It's piece of cake :)

Create main mvc master page, than create view and replace top line % Page ....

with

%@ Master Language="C#" MasterPageFile="~/Views/Shared/CMS.Master" Inherits="System.Web.Mvc.ViewMasterPage" %

this is going to be your second master page, insert your own place holders into asp:content tags

create view with second master page, done :)

9:04 am
Anonymous said...

hi,
I no see the difference between the difference between master page and the nested page in your sample.

10:41 pm

Post a Comment

Subscribe to: Post Comments (Atom)
 

AltStyle によって変換されたページ (->オリジナル) /