开发者

CSS and JavaScript in ASP.NET MVC 2 Pages

开发者 https://www.devze.com 2023-01-21 08:32 出处:网络
I have a master page that has two content sections like this (left some parts out): <head runat=\"server\">

I have a master page that has two content sections like this (left some parts out):

<head runat="server">
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder runat="server" ID="HeadContent" />
</head>

<body>
    <div id="content">
        <div id="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server" />
        </div>
    </div>
</body>

In one of my .aspx pages which references this master page, I supply the content like this (left some parts out):

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <% using (Html.BeginForm("Create", "Document", FormMethod.Post))
       { %>

       <p>
           <%: Html.LabelFor(m => m.Title) %>
           <%: Html.TextBoxFor(m => m.Title) %&g开发者_开发问答t;
           <%: Html.ValidationMessageFor(m => m.Title) %>
       </p>

       <p>
            <input type="submit" class="t-button t-state-default" value="Create" />
       </p>

    <% } %>


</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>

Yet the label created by the LabelFor chunk above does not get styled. In my CSS file, I have a rule to set the font globally and this is not applying - the font is defaulting instead.

Do I need to re-include all my CSS and Javascript in the 'Content2' section in the .aspx page? Isn't it sufficient to include them once in Site.Master?


You only need to include CSS and JavaScript references in the master page. The markup from both the master page and content pages are combined and sent as a single HTML document.

Your CSS probably doesn't match your markup properly so the styles aren't being applied correctly. You could add the CSS to your question for more assistance or use Firebug to inspect the source and styles.


Have you included a stylesheet rule for <label>?

Use a DOM inspector (Firebug, etc) to see where the label style (or lack thereof) is coming from.


I must define stylesheet rule for <label>, like this:

label { margin:10px; color:blue; }
0

精彩评论

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