Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop MVC creating a _Layout.cshtml and _ViewStart.cshtml file?

Every time I click to create a view or partial file Visual Studio automatically creates an _Layout.cshtml and an _ViewStart.cshtml file.

I do not want my project to create a _ViewStart.cshtml or a _Layout.cshtml file.

However it does. I looked at modifying the t4 code template but that seems like it is more to do with code generation rather than file generation.

Is there anyway to stop this behaviour?

like image 900
Exitos Avatar asked Mar 03 '14 09:03

Exitos


People also ask

What is the purpose of the _layout Cshtml file in the pages shared folder?

_Layout.cshtml This is used for common layout in web pages; it is like master page. The layout typically includes common user interface elements such as the app header, navigation or menu elements, and footer. Common HTML structures such as scripts and stylesheets are also frequently used by many pages within an app.

What is the difference between _viewimports Cshtml and _ViewStart Cshtml?

cshtml file. For _ViewImport. cshtml - the contents of this file applied to all the files present in the same folder and subfolder. So _ViewStart is execution whereas _ViewImport applies its content to each file.

What is _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. cshtml” page will assign the Layout page for it.

What is _layout Cshtml?

So, the _layout. cshtml would be a layout view of all the views included in Views and its subfolders. Setting Layout View in _ViewStart.cshtml. The _ViewStart. cshtml can also be created in the sub-folders of the View folder to set the default layout page for all the views included in that particular subfolder.


2 Answers

In short: You can not stop it, it is "hardcoded".

For more details: it's a "Convention over configuration" principle. The whole idea is to have framework preparing as much as possible in order to speed-up development process. You still have a flexibility to remove line:

Layout = "~/Views/Shared/_Layout.cshtml";

from you view and set to to:

Layout = null;

BTW, there is similar discussion here, it's possible duplicate subject.

like image 102
Kenan Zahirovic Avatar answered Sep 27 '22 17:09

Kenan Zahirovic


This question was partially answered here. The main idea is if you deleted _Layout.cshtml and _ViewStart.cshtml files, and then you create a new view and the option Use a layout page is checked, the studio will try to find a default layout, i.e., _Layout.cshtml and since it is not present in your project it will create a new one automatically along with_ViewStart.cshtml file. So to avoid this automatic creation make sure to uncheck Use a layout page every time you create a new view.

like image 37
Mykhailo Seniutovych Avatar answered Sep 27 '22 17:09

Mykhailo Seniutovych