Razor encodes string by default. Is there any special syntax for rendering without encoding?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- MVC-Routing,Why i can not ignore defaults,The matc
- Generic Generics in Managed C++
Use
@Html.Raw()
with caution as you may cause more trouble with encoding and security. I understand the use case as I had to do this myself, but carefully... Just avoid allowing all text through. For example only preserve/convert specific character sequences and always encode the rest:Then you have peace of mind that you haven't created a potential security hole and any special/foreign characters are displayed correctly in all browsers.
In case of ActionLink, it generally uses HttpUtility.Encode on the link text. In that case you can use
HttpUtility.HtmlDecode(myString)
it worked for me when using HtmlActionLink to decode the string that I wanted to pass. eg:As well as the already mentioned @Html.Raw(string) approach, if you output an MvcHtmlString it will not be encoded. This can be useful when adding your own extensions to the HtmlHelper, or when returning a value from your view model that you know may contain html.
For example, if your view model was:
For Core 1.0+ (and MVC 5+) use HtmlString
then
HTML RAW :
You can also use the WriteLiteral method