开发者

MVC 3: classic two-column layout with a header not showing in Site.Master

I am going for a classic two-column layout in Site.Master but nothing is happening. I have created a new _LayoutClient.cshtml file in Views/Shared folder and also a Site.Master file in the same folder. Going through normal process for controller class, I have a simple public ActionResult Index() method. When adding a new View file, I checked the 'Use a layout or master page: _LayoutClient.cshtml, for Index example (Index.cshtml)

for MVC3 there is _ViewStart.cshtml so as you know I don't need to follow the process of DRY. In my Site.Master file I have done the following code... (Site1.css is actually from Sportstore sample application from the Pro ASP.NET MVC 2 Framework by Steven Sanderson)

<asp:ContentPlaceHolder ID="head" run开发者_如何转开发at="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>

So I can only assume my CSS template is not being updated from Site.Master. I am using VS 2010, ASP.NET MVC 3 in C#. Please can someone have a look at tell me why there is no two-column layout. Thanks in advance. DB data is coming through.


You dont need to create a Site.Master.

Make sure you place the _LayoutClient.cshtml in the 'Shared' folder - you can copy the content of _Layout.cshtml to _LayoutClient.cshtml just as a starting point.

Change the following line to Site1.css:

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

You will also need to change _ViewStart.cshtml in your project root to point to your new layout i.e.

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

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜