ASP.NET MVC: Shared layout

asp.net-mvc, asp.net-mvc-4

Solution

I think you need a `_ViewStart.cshtml` in your `Views` folder which should have the following in it:

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

Problem

I have created a new empty ASP.NET MVC 4 project, and added a new folder `Shared` in `View` and new file `_Layout.cshtml` and put this code to that ``` <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>@ViewBag.Title</title> <script src="@Url.Content("~/Content/style.css")"></script> </head> <body> @RenderBody() </body> </html> ``` and now when I add new view for a controller it doesn't detect it as master page automatically as well as `Basic Template` ``` @{ ViewBag.Title = "AboutUs"; } <h2>AboutUs</h2> ``` it doesnt get `_Layout.cshtml` file as master page until I set that manually with `Layout = "~/Views/Shared/_Layout.cshtml";`

Original source