0

I'm using MVC 3 (the ASPX ViewModel) while I store and display data from my SQL database. I've tried using the raw input to store it as well as using HttpUtility.HtmlEncode. Neither are working when I try to display. I've tried using the HttpUtility.HtmlDecode as well as using <%: Model.MyHtmlVariable %>. Am I missing something?

Jason N. Gaylord
  • 7,910
  • 15
  • 56
  • 95
  • "not working" is generally a bad description for a problem. You should post some code because all 3 of your attempted techniques should display something on that page. – John Farrell Nov 03 '10 at 03:56
  • I would think it would be obvious enought that I'm not getting HTML. The title does say displaying HTML from a database. – Jason N. Gaylord Nov 03 '10 at 12:52
  • Well it wasn't obvious to me. At first glance this reads like MyHtmlVariable simply isn't populated. Just think of how clearer "is outputting encoded HTML" is vs "not working". – John Farrell Nov 03 '10 at 17:40
  • Fair enough. Thanks for the constructive criticism. :) – Jason N. Gaylord Nov 05 '10 at 18:37

2 Answers2

3

Using the traditional "<%= html %>" syntax should render it out for you but may not depending on what you're doing. If not, try to wrap it in an HtmlString object, like so:

<%= new HtmlString(html) %>

MVC should respect that and render it out properly.

If you're just looking to display the encoded HTML, the "<%: html %>" syntax is your friend

Jess Chadwick
  • 2,373
  • 2
  • 21
  • 24
0

You need to create a div to target and set the html using an jquery/javascript call to the controller action.

jQuery.get("/Controller/Action", 
     function(response) {  
          $("#MyDiv").html(response) 
     });  

See if something like that works.

Dave
  • 1,062
  • 8
  • 28