【问题标题】:MVC 3: classic two-column layout with a header not showing in Site.MasterMVC 3:Site.Master 中未显示标题的经典两列布局
【发布时间】:2011-06-02 03:14:54
【问题描述】:

我打算在 Site.Master 中使用经典的两列布局,但没有任何反应。我在 Views/Shared 文件夹中创建了一个新的 _LayoutClient.cshtml 文件,并在同一文件夹中创建了一个 Site.Master 文件。通过控制器类的正常过程,我有一个简单的公共 ActionResult Index() 方法。添加新视图文件时,我检查了'使用布局或母版页:_LayoutClient.cshtml,用于索引示例(Index.cshtml)

对于 MVC3,有 _ViewStart.cshtml,所以你知道我不需要遵循 DRY 的过程。在我的 Site.Master 文件中,我完成了以下代码... (Site1.css 实际上来自 Steven Sanderson 的 Pro ASP.NET MVC 2 框架的 Sportstore 示例应用程序)

<asp:ContentPlaceHolder ID="head" runat="server">
<link rel="Stylesheet" href="~/Content/Site1.css" type="text/css" />
</asp:ContentPlaceHolder>
</head>
  <body>
     <form id="form1" runat="server">
  <div>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
    <div id="header">
  <div class="title">My Project</div>
    </div>
    <div id="categories">
       Will put something useful here later
    </div>
    </asp:ContentPlaceHolder>
</div>
</form>

所以我只能假设我的 CSS 模板没有从 Site.Master 更新。我在 C# 中使用 VS 2010、ASP.NET MVC 3。请有人看看告诉我为什么没有两列布局。提前致谢。数据库数据正在通过。

【问题讨论】:

    标签: asp.net-mvc-3


    【解决方案1】:

    您不需要创建 Site.Master。

    确保将 _LayoutClient.cshtml 放在“Shared”文件夹中 - 您可以将 _Layout.cshtml 的内容复制到 _LayoutClient.cshtml 中作为起点。

    将以下行更改为 Site1.css:

    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    

    您还需要更改项目根目录中的 _ViewStart.cshtml 以指向您的新布局,即

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-15
      • 2022-11-22
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      相关资源
      最近更新 更多