Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can I return a model with a string propertie containing <li> elements and display it in view? If I just write @Model.Messages it shows all the string.. i need it in html format.
<li>
You can use the Content method with the Content-Type text/html to return the HTML directly, without the need of Html.Raw.
Content
text/html
Html.Raw
public ActionResult MyHtmlView() { return Content("<html><body>Ahoy.</body></html>", "text/html") }
You can pass whatever Content-Type you want, such text/xml.
text/xml
Add a comment
Use Server.HtmlEncode() to send html to view and then use the Server.HtmlDecode() to get the html to display on the view.
Server.HtmlEncode()
Server.HtmlDecode()
Then you can use @Html.Raw(Server.HtmlDecode(str)).
@Html.Raw(Server.HtmlDecode(str)).
Try this:
<div class='content'> @Html.Raw(HttpUtility.HtmlDecode(Model.Message)); </div>
Ref: Display encoded html with razor
You don't say which rendering engine you're using:
MVC3: @Html.Raw(Model.Description)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.