3

Possible Duplicate:
ASP.NET MVC Razor render without encoding

One of the proerties of my Product object is returning a string that has html in it. When I set the model to the view, the view reads it as text and not html. How do I let the view know to read the property as html?

<td colspan="2">
 <div>
   <label >                             
       @Model.LongDescription  
   </label>                                 
 </div>
</td>
Community
  • 1
  • 1
Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152

3 Answers3

9

Razor encodes everything by default, you just have to use @Html.Raw see this question which is pretty much the same problem you have

<td colspan="2">
 <div>
   <label >                             
       Html.Raw(@Model.LongDescription)
   </label>                                 
 </div>
</td>
Community
  • 1
  • 1
jorgehmv
  • 3,633
  • 3
  • 25
  • 39
0

Use Html.Raw helper method to ignore encoding

<label >                             
   @Html.Raw(Model.LongDescription)  
</label>  
Shyju
  • 214,206
  • 104
  • 411
  • 497
0

You need to use the HtmlString object. I prefer to handle this in my model by adding a property to the model:

public HtmlString LongDescription
{
    get
    {
        return new HtmlString(LongDescription);
    }
}

The object HtmlString will leave the html formatting in place for display.

Joel Etherton
  • 37,325
  • 10
  • 89
  • 104