5

I am having a Weird and annoying problem. In my ASP.NET MVC 5 project, time to time, I see that _ViewStart file and Shared/_Layout.cshtml files are created automatically even though I did not want. So, I deleted those files but these files are getting created time to time by itself. That cause a great problem because, sometimes, if I dont notice that these files are created, I can accidentally publish the website and then, after publish, I notice that all pages are being wrapped by the auto created _Layout.cshtml file. Is it a smart helping feature of Visual Studio 2013 ? Cant we stop this ?

Emran Hussain
  • 11,551
  • 5
  • 41
  • 48

1 Answers1

1

Emran!

I am not sure that you still need the answer but today I have also met similar problem. By some unknown reason file "Shared/_Layout.cshtml" was automatically added to my Project.

I was realy wondering why could it happen and I found which actions should be performed to make this file be created.


I have added new View to my Project and have used for it standard VS resources:

  1. Right mouse click on Views folder.
  2. Add -> Veiw...
  3. Inside window for adding view I have checked "Use a layout page" and have left field below empty.
  4. Press Add

My VS was thinking a lot and suddenly created new view and also... "Shared/_Layout.cshtml" and "Shared/_ViewStart.cshtml" files!! I do not think that this option might be switched off because it is logically to create layout page when it has been missed.

Hope this info is helpful for you and for anybody else :)

Evgenia
  • 86
  • 5
  • 2
    This answer is confusing. Are you saying your step-by-step process fixes the problem, or that it experiences the same problem as the OP? Did you find a way to add a View without it adding the `Shared\_Layout.cshtml` or `Shared\_ViewStart.cshtml` files? – John Washam Jan 22 '15 at 16:27
  • I'm on VS2022 now, and working on a project MVC 5 I'm also having this issue. Was wondering wtf was making those files do be generated. This explains it. Doesn't solve, but explains. – Fernando Wolff Jan 13 '22 at 16:12