0

I am returning Json data from a controller's action.

On the client, I am using jQuery templates where I bind data as follows:

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

The data returned from server contains P tags, I noticed that they are being displayed as encoded html tags.

How could I decode the data returned?

I am placing JavaScript in an external file so I won't be able to use @HTML.Raw() helper.

Thanks


I used this, however when checking on the page, I noticed the HTML is something as:

"

Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molis usitas camur, nostrud eros opes verto epulae feugiat ad. Suscipit modo magna letalis amet et tego accumsan facilisi, meus. Vindico luptatum blandit ulciscor mos caecus praesent sed meus velit si quis lobortis praemitto, uxor.

"

Notice the double quotes! Still, < p > tags are showing as tags and not being executed!

this is the Json being returned:

{"data":
[
    {
        "Title":"Need a Website?",
        "Body":"\u003cp\u003eConsequat te olim letalis premo ad hos olim odio olim indoles ut ve \u003c/p\u003e"
    }
]

}

1

2 Answers 2

2

Assuming I've understood your question correctly, your JSON response should be inserted into the page by jQuery, therefore the @HTML.Raw() MVC helper is irrelevant here.

Try the following code:

var result = $("#jobsTmpl").html(results.data);
Sign up to request clarification or add additional context in comments.

Comments

1

I solved this issue in configuring jQuery Template Plugin:

{{html Body}}

This way, text will be decoded and displayed properly.

1 Comment

Please accept your own answer to make it noticed by others who view the thread! :)

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.