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.
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
There is actually a way to do this. Scott Hansleman has a blog post on the topic: http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
It's a bit hackish, but doable. I think the approach described could be encapsulated and cleaned up even further so that you could build your views and controllers without worrying about how things are being wired together.
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.
Support for .NET User Controls in MVC
MVC does not officially support .Net User Controls but you can retrieve the html produced by them. The following code retrieves the HTML produced from a page made up of dozens of ASCX files.
Code example:
In Razor you can achieve the same functionality using Layout pages.
Layout/Master pages using Razor
Having just been through this process myself, I found that this method by Matt Hawley worked a treat.
This approach works by creating a standard aspx page that uses your required master page. You can then add content placeholders as required. You then call RenderPartial with the name of the view to use. The response from your controller then gets passed on down to the actual view you want to render.
There is a bit more plumbing required to make this work and you have to call an extensions method to render your view in the controller but once you are setup it works very well.