Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a certain View in MVC not inherit _Layout.cshtml?

I'm using ASP.NET MVC5, razor syntax. I need a specific "Create" view to NOT inherit the _Layout.cshtml Shared View.

Basically, in this particular View, I don't want any of the _Layout.cshtml features like the navigation menu, footer, etc.

like image 396
Mike Marks Avatar asked Jan 02 '14 20:01

Mike Marks


People also ask

What is the use of _ViewStart Cshtml in MVC?

The _ViewStart. cshtml page is a special view page containing the statement declaration to include the Layout page. Instead of declaring the Layout page in every view page, we can use the _ViewStart page. When a View Page Start is running, the “_ViewStart.

What is the use of _layout Cshtml in MVC?

The file "_Layout. cshtml" represents the layout of each page in the application. Right-click on the Shared folder in Solution Explorer then go to "Add" item and click on "View". Now the View has been created.

How do you specify a common layout for all views?

The default _ViewStart. cshtml is included in the Views folder. It can also be created in all other Views sub-folders. It is used to specify common settings for all the views under a folder and sub-folders where it is created.

What is _ViewImports Cshtml?

The _ViewImports. cshtml file for an ASP.NET Core MVC app is typically placed in the Pages (or Views) folder. A _ViewImports. cshtml file can be placed within any folder, in which case it will only be applied to pages or views within that folder and its subfolders.


2 Answers

Use.

@{
    Layout = null
}

In whatever .cshtml file you don't want to inherit the _layout.cshtml

like image 151
Nico Avatar answered Sep 27 '22 18:09

Nico


It inherits Layout because of your _ViewStart.cshtml file. Look at your ViewStart and delete related line. Then if you want to use Layout in your page you have to specify your Layout in each page.

like image 20
Selman Genç Avatar answered Sep 27 '22 18:09

Selman Genç