Render HTML saved in a SQLServer database field

2

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
    source

    1 answer

    2

    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

    Example

    @Html.Raw("<span>StarWars!</span>")
    

    In your case

     @Html.Raw(miHtml)
    

    Links that can help you

    I hope it will help or guide you.

        
    answered by 14.02.2018 / 18:19
    source