Why is MVC 4 Razor escaping ampersand when using HTML.Raw in a title attribute

后端 未结 2 1521
清歌不尽
清歌不尽 2020-12-16 01:51

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,

相关标签:
2条回答
  • 2020-12-16 02:24

    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>
    

    Results in:

    <a title="Show Size 6&#189;-8">Test</a>
    
    0 讨论(0)
  • 2020-12-16 02:26

    If you can't do the workaround listed above, I have a patched base-class you could try injecting via web.config. Check it out at https://gist.github.com/4036121

    0 讨论(0)
提交回复
热议问题