views:

202

answers:

2

Okay, so maybe this is a no no in the MVC pattern in which case, that's the answer I'm looking for. However, let's say I have some content html in a database and I want to pass it through to the view. I am assuming I could use a ViewData property to pass this through to the page. What sort of massaging do I need to do to the string to get something like <h1>Hello World</h1> to show up as 'Hello World' instead of '<h1>Hello World</h1>'.

A: 

You'd need to strip out the HTML before you put the string into the ViewData.

EDIT: When you print the ViewData directly to the page, it shouldn't escape the HTML markup.


<%=ViewData["whatever"]%>

That's C#, but it's very similar in VB.NET.

mgroves
I want the html in the string to be interpreted as html when it gets to the page.
Anthony Potts
+2  A: 

Nothing, just do <%=ViewData["yourkey"] %> instead of <%=Html.Encode(ViewData["yourkey"]) %> in your view.

Note: Only do this if you are absolutely sure you trust the data in the database!

svinto
That's great...you mean looking at the code might actually help? But seriously, thanks for pointing out the obvious in a way that didn't make me feel stupid.
Anthony Potts