I have a layout page (or master page) with MVC 3 and would like to make my views sort of content pages to this layout page, but alas I have no clue how to do this
I am totally new to MVC 3 and this may sound as a stupid question but I can't find anything relating 开发者_JS百科to this.
In your view code, you would simply set the layout file. Assuming your Layout is named _Layout.cshtml
and stored in /Views/Shared
, the code might be:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
in MVC 3 we can set the layout page for the current view by doing this one
@{
ViewBag.Title = "Home page";
Layout = "../Shared/_Layout.cshtml";
}
if application need the same layout everywhere in application you can set them for whole application by making a _ViewStart.cshtml
in views folder and place this one.
@{
Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
first code can be apply in the views for setting the layout for page only you have. or second can be apply in _ViewStart.cshtml in Views directories of your application.
Also, when you create new view you can select a "master page" for it. By default it's whatever "_ViewStart.cshtml" is linking to.
精彩评论