Render HTML saved in a SQLServer database field


I have HTML saved as Varchar in a SQL Server database. I'm trying to insert this HTML in a view but in doing so, it is passed as text and not as HTML (BUT, HTML adds double quotes at the beginning and end, which does not allow rendering.

The HTML in question is being saved in a string in my controller, which is passed as a parameter to the view.

I've already tried:

  • HttpUtility.Encode (miHtml)
  • the data annotation [DataType (DataType.HTML)]
  • asked by Leandro hereñu 14.02.2018 в 18:08

    1 answer


    By default Razor encodes strings for this reason you can not directly embed the text as HTML. It's for a security reason ... imagine writing scripting code "unwittingly"

    In order to write raw HTML, there is the helper .Raw



    In your case


    Links that can help you

    I hope it will help or guide you.

    answered by 14.02.2018 / 18:19