MVC 3 razor layout

2019-02-16 09:51发布

问题:

I have a MVC 3 project in which I use _Layout.cshtml as master page in all web pages. Now I want to remove this master page (layout) from one of the page (progress.cshtml). So I removed the removed the top portion of the page which was

@{
    ViewBag.Title = "Progress";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

I thought this will work but when I browse progress page it still shows the content from layout file. How I can remove this binding?

回答1:

Set the layout= null to remove the default layout inheritance in that view



回答2:

the issue is there is a file named _viewstart.cshtml which behave as the config file to know the engine which is the masterfile.

For more info have a look:

http://weblogs.asp.net/gunnarpeipman/archive/2010/10/10/asp-net-mvc-3-beta-view-start-files-for-razor-view-engine.aspx

Thanks



回答3:

@{
ViewBag.Title = "Progress";
Layout = null;
}