Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# ASP.NET MVC Basics Adding a List Page Finishing the List View

ViewStart file does not get created

Whenever I add the Index View, the ViewStart file never gets created. If I create it myself, it is not linked tot he Index view, and does not load the layout. It only loads the layout if I enter the layout reference like we did in the Detail view. I haven't been able to find a solution to this issue online. Is there a setting I would need to change to get this file created properly? Also, I do have the checkbox checked for "Use a layout or master page:."

2 Answers

Jonathan Padilla
Jonathan Padilla
5,493 Points

My guess is you created the new View file on your own by right clicking on the Views/ComicBooks folder and creating your Index.cshtml file there.

The _ViewStart.cshtml file is only created when right clicking the public ActionResult Index() method within the ComicBooksController.cs file and selecting the Add View option (with the Use a layout page checked).

Late follow up but I hopes it sheds some light on what may have happened here.

James Churchill
STAFF
James Churchill
Treehouse Teacher

Brandon,

1) When you created your ASP.NET project, what project template did you use? 2) Can you share your project? Can you post it to a public GitHub repo?

I'd make sure that the name of the name of the file is "_ViewStart.cshtml" and that it's located in the "Views" folder. Here's an example of the contents:

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

Thanks ~James