【问题标题】:<% this.Parameter %> inside quotes; ASP variable not getting displayed on page correctly when used inside quotes<% this.Parameter %> 内引号;在引号内使用时 ASP 变量未正确显示在页面上
【发布时间】:2015-03-03 09:13:07
【问题描述】:

在我的母版页上,我有一个元标记,其值是逐页更改。这是我的标签:

<meta name="Description" content="<%= this.MetaDescription %>">

但是,引号似乎导致该值在页面上按字面解释;当我检查页面的 html 时,它显示“content=''”而不是“content='[Value of this.MetaDescription]'”

当变量放在引号内时,如何让它正确解释变量?

【问题讨论】:

  • 你的代码中的MetaDescription 有值吗?我的意思是你是否在你的类后面的代码中为这个属性设置了一个值?
  • 是的,我这样做了,而且我已经通过逐步检查确保我的参数设置正确。
  • MetaDescription是什么类型的变量?

标签: c# asp.net variables parameters quotes


【解决方案1】:

试试这个:

content=<%='"' + this.MetaDescription + '"'%>

如果例如this.MetaDescription 在代码隐藏中设置为 'SomeString',然后将生成以下标记并将其发送回客户端:

content = "SomeString"

似乎&lt;%= %&gt; 运算符用引号括起来时根本不计算。相反,引号之间的内容被发送回客户端。

【讨论】:

    猜你喜欢
    • 2013-11-19
    • 1970-01-01
    • 2012-02-21
    • 2012-05-17
    • 2014-12-31
    • 2015-06-03
    • 1970-01-01
    • 2022-10-02
    • 1970-01-01
    相关资源
    最近更新 更多