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"
    }
]

}

Gordon
  • 312,688
  • 75
  • 539
  • 559
Bill
  • 2,026
  • 9
  • 55
  • 99
  • 1
    possible duplicate of [Jquery decode HTML entities](http://stackoverflow.com/questions/1147359/jquery-decode-html-entities) – Blazemonger Nov 16 '11 at 15:01

2 Answers2

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);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
1

I solved this issue in configuring jQuery Template Plugin:

{{html Body}}

This way, text will be decoded and displayed properly.

Bill
  • 2,026
  • 9
  • 55
  • 99