views:

225

answers:

2

Is it possible to keep my existing .master page and have it used with a new ASP.NET MVC 3 Razor view? I tried this:

@{
   LayoutPage = "~/Views/Shared/Site.master";
 }

And it gives me this error message:

The file '~/Views/Shared/Site.master' could not be rendered, because it does not exist or is not a valid page.

+4  A: 

I think you need to look for _Layout.cshtml in the shared folder...

Here is the comparison between aspx and razor view engine....

http://weblogs.asp.net/shijuvarghese/archive/2010/07/29/aspx-and-razor-view-engines-in-asp-net-mvc-3-preview-1.aspx

this is also an interessting post about nested masterpages with razor...

http://weblogs.asp.net/fredriknormen/archive/2010/08/01/asp-net-mvc-3-0-preview-1-razor-and-nested-master-pages.aspx

HTH

server info
Your suggestion of using _Layout.cshtml would mean I would have to convert my existing master page and all other pages over. Or I would have to duplicate my master page (one in Razor, one in Web Form Engine). Hoping to avoid that (since I can already mix Razor partial views with no problems)
thekaido
+3  A: 

Unfortunately no. Master pages are a part of the ASPX WebForms view engine, not the MVC framework so Razor cannot interoperate with it.

One option would be to duplicate the masters, as you mentioned, but rather than copying all the code, you could factor the Master page into a bunch of ASPX partials that the Razor and ASPX masters could embed. Then you can start converting each page and partial, one-by-one, to Razor and eventually get rid of the ASPX master.

anurse