Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Html.DisplayFor display HTML I read from the DB?

Tags:

asp.net-mvc

I am using a CKEditor on my MVC project. I'm saving HTML into the DB. WHen I read it and display it on screen, what I get is

   <p> <a href="http://www.cnh.com">www.cnh.com</a></p> <p>  </p>

I use Html.DisplayFor.

<td>
    @Html.DisplayFor(modelItem => item.SampleCollectionInstructions)
</td>

How can I make it display the links properly and one per line??

like image 511
Rui Martins Avatar asked Nov 13 '12 12:11

Rui Martins


2 Answers

Use Raw method to return markup without html encoded Ex;

@Html.Raw("<div>Some text</div>")
like image 155
Kaf Avatar answered Nov 20 '22 21:11

Kaf


If anyone else is confused about doing this in loops, like I was:

You can just omit both DisplayFor and modelItem =>, so:

@Html.Raw(item.SampleCollectionInstructions)
like image 5
MGOwen Avatar answered Nov 20 '22 21:11

MGOwen