1

I have html code in database. my model gets assign with correct data from database. but when displaying on page its not there.

my model:

public class myModel
{
   public string id {get; set;}
   public string data {get; set;}
}

my view :

<div id="tabs1">
  <ul>
    <li><a href="#tab1">firsttab</a></li>
  </ul>

   <div id="tabl">
      <p><%= Model.data%></p>
   </div>
</div>

Please note data is HTML data. and i am using JqueryUI widget TABS. here is data example:

   <DIV><B>Edited by USER NAME on Tuesday, January 31, 2012 at 12:11 PM</B><BR> </DIV>

when i try to run this code on my local machine it works fine. but when i deploy to server this data is not rendering.

any thoughts? Thank you in advance.

2
  • Did you forget the @ before model, or is it not needed in .net mvc 2? @Model.data, that is. Commented Apr 18, 2012 at 21:01
  • @DanielHqHallqvist this is MVC2 ... Commented Apr 18, 2012 at 21:02

2 Answers 2

1

You can use Html.Raw() in MVC3+:

<div id="tabl">
   <p><% Html.Raw(Model.data) %></p>
</div>

Use MvcHtmlString.Create in MVC2:

<div id="tabl">
   <p><%: MvcHtmlString.Create(Model.data) %></p>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

i found it.. it was connection issue. thank you guys... it was helpfull information.
1

Description

You have to use Html.Raw to output html.

Html.Raw Returns markup that is not HTML encoded.

Sample

<%= Html.Raw(Model.data) %>

More Information

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.