我打算在Site.Master中使用经典的两列布局,但是什么也没有发生。我在Views/Shared文件夹中创建了一个新的_LayoutClient.cshtml文件,并在同一文件夹中创建了一个Site.Master文件。通过控制器类的正常过程,我有一个简单的公共ActionResult索引()方法。在添加新的视图文件时,我选中了“使用布局或母版页:索引示例(Index.cshtml)的_LayoutClient.cshtml”。
对于MVC3,有_ViewStart.cshtml,所以您知道我不需要遵循DRY的过程。在我的Site.Master文件中,我完成了以下代码...(Site1.css实际上来自Steven Sanderson的专业ASP.NET MVC2框架中的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#中使用VS2010,ASP.NET MVC3。请有人看一下,告诉我为什么没有两栏布局。提前谢谢。数据库数据正在传输中。
发布于 2011-06-02 03:14:54
您不需要创建Site.Master。
请确保将_LayoutClient.cshtml放在“共享”文件夹中--您可以将_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";
}希望能有所帮助
https://stackoverflow.com/questions/5792130
复制相似问题