3

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";

1 Answer 1

16

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

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.