24

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

1
  • 6
    "its not working" (sic) isn't enough description. Please read tinyurl.com/so-hints and edit your question. Commented Mar 4, 2012 at 15:13

1 Answer 1

57

kindly try this:

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

and let me know if it worked.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
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.
appreciate it , glade that you are smiling :)
@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)
This ended up working for me as well, is there an explanation as to why this is needed somewhere?

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.