1

I have a string returned from server with encoded HTML tags.

I use the following:

var result = $("#jobsTmpl").tmpl(results.data);
$("#jobsContainer").html(result);

In the template I am using the following for the string that contains the HTML encoded: {{html Body}}

I also tried ${Body} with no luck.

What's happening is that, the HTML string is displayed as encoded HTML, I just want to have the HTML take effect

Thanks

1 Answer 1

4

check this out... http://api.jquery.com/template-tag-html/

basically where you want your string to be rendered as html and not encoded on the client you change

${NameOfProperty}

to

{{html NameOfProperty}}

If you are doing this and you are still getting encoded html, you need to change the server side code, as if your templates are as above then its not a problem on the client.

Sounds like your server side code is outputting your html tags encoded to display instead of render. In a Razor view you can use

@Html.Raw(Model.NameOfProperty)

in asp.net generally you can use

string unEncodedHtml = Server.HtmlDecode(htmlEncoded);

But really you should work out where / how its getting encoded in the first place, no point encoding then decoding.

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

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.