Reputation: 29720
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?
Upvotes: 9
Views: 1899
Reputation: 3691
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.
Upvotes: 2
Reputation: 1597
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.
Upvotes: 4