23

I have some html stored in a table. here is some sample data

<p><span style="font-size: small; color: #ff0000;"><span style="font-size: small;"> <span style="font-size: large; color: #000000;">ਮਾਂ</span><br />  <br />ਚਾਵਾਂ ਸਧਰਾਂ ਦੇ ਨਾਲ ਮਾਏ ਜੋ ਤੂੰ ਬੂਟਾ ਲਾਇਆ,<br />ਦੇ ਮਮਤਾ ਦਾ ਪਾਣੀ ਅੱਜ ਓਹ ਭਰ ਜੋਬਨ ਤੇ ਆਇਆ,<br />

I am trying to display on page, I am using asp.net mvc razor view and using

@Html.Raw(blog.Body)

but its not working. can someone help, what is the reason.

Thanks

Parminder

Parminder
  • 3,088
  • 6
  • 37
  • 61
  • 6
    "its not working" (sic) isn't enough description. Please read http://tinyurl.com/so-hints and edit your question. – Jon Skeet Mar 04 '12 at 15:13

1 Answers1

56

kindly try this:

@Html.Raw(HttpUtility.HtmlDecode(blog.Body));

and let me know if it worked.

Mohammed Swillam
  • 9,119
  • 4
  • 36
  • 47
  • 6
    What happens when someone posts JavaScript to the blog? You really should sanitize the HTML unless you can guarantee script will never make it into the DB. SO is all about recycling questions, now folks will read this and think it's OK to use Raw. – RickAndMSFT Mar 04 '12 at 21:06
  • Yes, I marked it as an answer. Thanks a lot. Rick thanks a lot for your suggestion, I have already taking care of that. Thanks again. – Parminder Mar 05 '12 at 03:41
  • appreciate it , glade that you are smiling :) – Mohammed Swillam Mar 05 '12 at 15:18
  • 1
    @RickAndMSFT: Your Point is very valid and relevant. I would be happy if you could provide it as POST / answer( including how to prevent it / handle the html input to save to db) – Shyju Aug 08 '12 at 14:54
  • 1
    This ended up working for me as well, is there an explanation as to why this is needed somewhere? – War Gravy Mar 11 '16 at 21:10