How to render MvcHtmlString as HTML

I get MvcHtmlString as a model for my view. And I need to display this line as HTML. At the moment, I tried:

@Model.ToHtmlString() 

But that gives me the text on my page. I know this should be like a trivial answer. But I can’t get it =)

+6
c # asp.net-mvc-3 razor
source share
2 answers

You need to use the Html.Raw helper:

 @Html.Raw(Model.ToHtmlString()) 
+13
source share

try using

 @(Model) 

and implement the ToHtmlString() method in the class

+2
source share

All Articles