代码之家  ›  专栏  ›  技术社区  ›  salgiza

母版页(MVC2)的HTML标题标记中的ContentPlaceHolder有一个奇怪的问题

  •  7
  • salgiza  · 技术社区  · 14 年前

    好吧,我肯定我犯了个愚蠢的错误,但我找不到问题出在哪里,这让我发疯了。

    <head runat="server">
        <title>
           <asp:ContentPlaceHolder ID="TitleContent" runat="server" /> - Company
        </title>
    </head>
    

    它只是VS在创建母版页时插入的默认HTML,我只是在最后添加了“-Company”,这样我就不必在每个视图中重复该文本。

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        Some title for the view
    </asp:Content>
    

    <title>Some title for the View - Company</title>
    

    我得到:

    <title>Some title for the View</title>
    

    为什么?

    3 回复  |  直到 14 年前
        1
  •  5
  •   Erik Philips    14 年前

    Phil Haacked on Title Tags and Master Pages 是一本好书。

    <head runat="server">
    

    <head>
    

        2
  •  3
  •   Chris    14 年前

    在您的标题标签中尝试以下操作:

    <asp:ContentPlaceHolder ID="TitleContent" runat="server" /><%= " - Company" %>
    

        3
  •  0
  •   Anthony Potts    14 年前

    在MVC中,我不记得曾经使用过ContentPlaceHolder。我强烈地键入我的母版页并以这种方式填充母版页。