【问题标题】:ASP.NET MVC: Shared layoutASP.NET MVC:共享布局
【发布时间】:2016-03-09 06:31:57
【问题描述】:

我创建了一个新的空 ASP.NET MVC 4 项目,并在 View 和新文件 _Layout.cshtml 中添加了一个新文件夹 Shared 并将此代码放入其中

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

现在当我为控制器添加新视图时,它不会自动将其检测为母版页以及Basic Template

@{
    ViewBag.Title = "AboutUs";
}

<h2>AboutUs</h2>

在我使用 Layout = "~/Views/Shared/_Layout.cshtml"; 手动设置之前,它不会将 _Layout.cshtml 文件作为母版页

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    我认为您的Views 文件夹中需要一个_ViewStart.cshtml,其中应包含以下内容:

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

    【讨论】:

      猜你喜欢
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 2012-11-20
      • 2021-11-10
      相关资源
      最近更新 更多