3

Closed

Html.Raw used as attribute value in Razor is still being encoded

description

Steps:
  • Load an MVC 4 project.
  • Go into a view (e.g., ~/Views/Shared/_Layout.cshtml).
  • Add an attribute to an HTML element and make its value something that is already attribute-encoded and wrapped in @Html.Raw.
  • Run site and find the title attribute is encoded, despite being run through @Html.Raw.
Example:
<a title="@Html.Raw("Show Size 6½-8")">Test1</a>
Expected:
<a title="Show Size 6½-8">Test1</a>
Actual (doubly-encoded somehow):
<a title="Show Size 6½-8">Test1</a>
[Original Stack Overflow question: http://stackoverflow.com/q/12321616/48700]
Closed Aug 10, 2013 at 12:44 AM by yjhong
verified.

comments

anurse wrote Nov 8, 2012 at 1:19 AM

Yep, there's a bug here. I've got patched WebViewPage base classes here: https://gist.github.com/4036121 which can help work-around the problem. We'll put it on our queue for the next release!

nowakra wrote Aug 6, 2013 at 10:13 PM

Checked in a fix: a967101..50ecb74

JohnVins wrote Tue at 3:41 PM

We are using Razor runtime version v4.0.30319, and this bug is still not fixed. Why is this item closed?

JohnVins wrote Tue at 3:45 PM

Just noticed this is marked as fixed in version 5.0 RC. Why so late of a version? The currently available version in Nuget from MS is version 3.2.2.