不确定如果可能,但我在课堂上有这个:
public string TextNotIncluded
{
get
{
return ("which is <u>not</u> included in the Quote");
}
}
Run Code Online (Sandbox Code Playgroud)
在<u>与</u>被显示在我看来,而非字不被强调.我不熟悉C#.
任何人都可以提供快速解答吗?
谢谢.
编辑:
我只是在我的观点中这样说:@MyClass.TextNotIncluded.@Html.Raw在我的情况下,将它包装起来并不高效,因为我在整个数十个视图中都散布了它.
这样做没有任何根本性的错误,但它可能无法呈现您期望的方式.
您可以@Html.Raw像其他人建议的那样使用,但我认为最好以表明它可能包含html的方式显式声明您的模型.您可能希望使用MvcHtmlString该类来代替:
public MvcHtmlString TextNotIncluded
{
get { return MvcHtmlString.Create("which is <u>not</u> included in the Quote"); }
}
Run Code Online (Sandbox Code Playgroud)
然后在您的视图中,您可以使用:
@Model.TextNotIncluded
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Razor,默认情况下字符串是HTML编码的 - 您需要使用它Html.Raw来关闭编码:
@Html.Raw(x.TextNotIncluded)
Run Code Online (Sandbox Code Playgroud)
在ASPX引擎中,您将使用 <%= %>
<%= x.TextNotIncluded %> - this gives you the raw text
<%: x.TextNotIncluded %> - this HTML-encodes your text - you don't want this.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11366 次 |
| 最近记录: |