使用asp.net文字和元标记的占位符

时间:2013-07-02 13:02:05

标签: asp.net tags literals meta

我正在尝试使用文字和占位符来实现允许添加元标记(例如描述或关键字)的母版页。我正在使用以下代码。

Just for further info:
" is used for double quotes
/ is slash (/)


<!-- description in master page -->
<asp:Literal ID="descriptionStart" runat="server" Text="<meta name=&quot;description&quot; content=&quot;test" />
<asp:ContentPlaceHolder ID="metaDescription" runat="server" />
<asp:Literal ID="descriptionEnd" runat="server" Text="&quot; &#47;>"/>
<!-- end of description -->


In my content page I add description as follows:
<asp:Content ID="metaDescription" ContentPlaceHolderID="metaDescription" runat="server">
This is a test description
</asp:Content>


IE View code shows this:
<!-- description in master page -->
<meta name="description" content="

This is a test description

" />
<!-- end of description -->

看起来ASP.Net正在为lietrals添加换行符。是否可以在元描述标签的同一行显示描述?

Based on one comment I received Alexander, I modified the code for master page.  It's enclosing placeholder in single quotes.
<!-- description -->
<meta name="description" content='<asp:ContentPlaceHolder ID="metaDescription" runat="server" />' />
<!-- end of description -->

Here is the output of IE view code after the change:
<!-- description -->
<meta name="description" content='This is a test description' />
<!-- end of description -->

1 个答案:

答案 0 :(得分:0)

基本上,你已经添加了换行符,因为你的三个控件都是从一个新行开始的。将它们彼此相邻放在一行中,具体取决于您应该执行的编码。

我相信你不需要Literals,你是否试过写开始和结束标签?