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>
0

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

0

Use Html.Raw helper method to ignore encoding

<label >                             
   @Html.Raw(Model.LongDescription)  
</label>  

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.