Html.Raw is not working asp.net mvc

27,467

kindly try this:

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

and let me know if it worked.

Share:
27,467

Related videos on Youtube

Parminder
Author by

Parminder

Dont know what to say....

Updated on January 15, 2020

Comments

  • Parminder
    Parminder over 4 years

    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

    • Jon Skeet
      Jon Skeet about 12 years
      "its not working" (sic) isn't enough description. Please read tinyurl.com/so-hints and edit your question.
  • RickAndMSFT
    RickAndMSFT about 12 years
    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.
  • Parminder
    Parminder about 12 years
    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.
  • Mohammed Swillam
    Mohammed Swillam about 12 years
    appreciate it , glade that you are smiling :)
  • Dushan Perera
    Dushan Perera over 11 years
    @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)
  • War Gravy
    War Gravy about 8 years
    This ended up working for me as well, is there an explanation as to why this is needed somewhere?