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?

4
  • "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. Commented Nov 3, 2010 at 3:56
  • I would think it would be obvious enought that I'm not getting HTML. The title does say displaying HTML from a database. Commented Nov 3, 2010 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". Commented Nov 3, 2010 at 17:40
  • Fair enough. Thanks for the constructive criticism. :) Commented Nov 5, 2010 at 18:37

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Jess! Also, someone had pointed out to use a method that resturns an IHtmlString to keep consistency of the inline code.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.