I'm using Razor in MVC 3 and Asp.net C#.
I have a View with the following code. model.ContentBody
has some HTML tags.
I would need display this HTML content as DECODED.
How shall I change my code in the View?
<div class="display-field"> @Html.DisplayFor(model => model.ContentBody) </div>
You add code to a page using the @ character When you display content in a page using the @ character, as in the preceding examples, ASP.NET HTML-encodes the output.
HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as < and > for HTTP transmission.
HtmlEncode is only meant to encode characters for display in HTML. It specifically does not encode whitespace characters. I would go with your first option, and make it an extension method for HtmlHelper.
Razor is one of the view engines supported in ASP.NET MVC. Razor allows you to write a mix of HTML and server-side code using C# or Visual Basic.
<div class="display-field"> @Html.Raw(Model.ContentBody) </div>
This code solved the problem!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With