razor - Is it possible to display raw Html from database in ASP.NET MVC 3? -
i have table in db 1 of properties html page (without html, head , body tags), , intend put in middle of 1 of views - say, call cotroller method takes argument, , return view passing html big string model. searched (not much, admit), , found following method:
<%= system.web.httputility.htmldecode(yourencodedhtmlfromyoudatabase) %>
that found here in stackoverflow. when tried similar razor aproach, ended this:
@system.web.httputility.htmldecode("<h1>test</h1>")
that's idea, didn't work quite planned.
all need is: @html.raw(yourencodedhtmlfromyoudatabase)
i'm assuming html in database has been sanitized (or @ least reliable source), because if not, opening cross-site scripting attacks.
the reason approach didn't work razor html-encodes output default (every time use @
display something). html.raw
tells razor trust html , want display without encoding (as it's raw html).
Comments
Post a Comment