Take the 2-minute tour ×

I am displaying my 'news' page and I want the customer to be able to output some simple html.

My view looks like this:

@using SuburbanCustPortal.SuburbanService

    <br />

    @foreach (var item in (IEnumerable<TokenNews>) ViewBag.News)
      <div class="fulldiv">

When I do it this away, the html isn't being rendered by the browser, it's just showing the html as text.

Any way that I can output the html where the browser will render it?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You didn't exactly specify what part is being shown as text, but if it's item.Body, do @Html.Raw(item.Body) instead. That turns a string into an IHtmlString, whose purpose is to tell Razor that this thing is guaranteed to be safe to output as-is, and will not contain nasties like XSS attacks (ensuring this when using Html.Raw is your job). Everything that is not an IHtmlString will be escaped automatically by Razor.

share|improve this answer
yup body was it. That worked perfectly! tyvm! couple of minutes before I can accept it but I will –  ErocM Dec 30 '12 at 19:08
add comment

Your Answer


