Reputation: 4331
I have an ASP.NET master page that contains a lot of important display logic for my application. Now I'm being called upon to use that same master page with an MVC4 application. It looks okay at first when I simply use the <%@ Master %> tag in my Site.Master file, but it looks as though my MVC code can't access or modify the content of the master page, the way I'm used to doing with an ASP.NET content page.
In particular, it seems that my MVC code executes only after the ASP.NET master has been completely rendered.
My two-part question is:
Thank you.
Upvotes: 0
Views: 2726
Reputation: 107
You need to create a layout html file that contains the basic structure of the page (same as the masterpage).
Then in your views you can reference the layout using
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
If you create a new ASP.Net MVC Project you have the structure already, you should only change the _layout.cshtml file adding the code you need.
To expand a little bit more on you questions, here's an article from scott hansleman about the differences between mvc and aspnet http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
Upvotes: 1