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.
Related videos on Youtube
Comments
-
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;">&nbsp;<span style="font-size: large; color: #000000;">ਮਾਂ</span><br />&nbsp; <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 about 12 years"its not working" (sic) isn't enough description. Please read tinyurl.com/so-hints and edit your question.
-
-
RickAndMSFT about 12 yearsWhat 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 about 12 yearsYes, 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 about 12 yearsappreciate it , glade that you are smiling :)
-
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 about 8 yearsThis ended up working for me as well, is there an explanation as to why this is needed somewhere?