我创建了一个新的空 ASP.NET MVC 4 项目,并在 View
中添加了一个新文件夹 Shared
和新文件 _Layout.cshtml
并将此代码放入其中
<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>
现在,当我为 Controller 添加新 View 时,它不会自动将其检测为母版页以及基本模板
@{
ViewBag.Title = "AboutUs";
}
<h2>AboutUs</h2>
它不会将 _Layout.cshtml
文件作为母版页,直到我使用 Layout = "~/Views/Shared/_Layout.cshtml"; 手动设置该文件;
最佳答案
我认为您的 Views
文件夹中需要一个 _ViewStart.cshtml
,其中应包含以下内容:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
关于asp.net-mvc - ASP.NET MVC : Shared layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18110863/