I have HTML saved as Varchar in a SQL Server database. I'm trying to insert this HTML into a view but when I do, it is passed as text and not as HTML (I mean, it adds double quotes to the HTML at the beginning and at the end, which does not render it possible.
I am saving the HTML in question in a string in my controller, which is passed as a parameter to the view.
I already tried:
- HttpUtility.Encode(myHtml)
- the data annotation [DataType(DataType.HTML)]
By default Razor encodes strings for this reason you cannot directly embed the text as HTML. It's for a security reason... imagine writing scripting code "unintentionally"
To be able to write raw HTML, there is the .Raw helper
Example
in your case
Links that can help you
I hope it helps or guides you.