本文介绍了为什么在title属性使用HTML.Raw时MVC 4剃刀逃逸符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近升级到MVC 4,现在我们有我们的链接标题无法正确显示。问题是之前HTML.Raw不会逃避&功放;在我们的title属性,但现在它。下面是我的示例code:

We recently upgraded to MVC 4 and now we are having titles in our links not display correctly. The problem is before HTML.Raw would not escape & in our title attributes, but now it does. Below is my sample code:

<a title="@Html.Raw("Shoe Size 6&#189;-8")">Test</a>

将会产生以下标记:

Which produces the following markup:

<a title="Shoe Size 6&amp;#189;-8">Test</a>

我发现这样唯一的解决办法为止是把整个锚成一个字符串,然后HTML.Raw该字符串。

The only solution I found so far was to put the entire anchor into a string and then HTML.Raw that string.

Why是Html.Raw转义锚标记符号在ASP.NET MVC 4?。

这是一个非常丑陋的解决方案,我希望有一个更好的选择。

This is a very ugly solution and I am hoping there is a better alternative.

推荐答案

虽然只是一小步,少丑陋的解决方法,你可以简单地 @ Html.Raw 全属性名称和值。

While it is only a small step less ugly workaround, you can simply @Html.Raw the full attribute name and value.

<a @Html.Raw("title=\"Show Size 6&#189;-8\"")>Test</a>

结果:

<a title="Show Size 6&#189;-8">Test</a>

这篇关于为什么在title属性使用HTML.Raw时MVC 4剃刀逃逸符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:55