Click to See Complete Forum and Search --> : MVC and jQuery


r3plica
01-09-2012, 07:49 AM
This is doing my nut in.
I have this simple jquery code in my app:


<script type="text/javascript">
$(document).ready(function () {
var items = @ViewData["items"];

$.each(items, function() {
$.each(this, function(index, item) {
alert(item);
});
});
});
</script>


If I view this in FireBug the variable "items" looks like this:


var items = [{&quot;ImagePath&quot;:&quot;44610855-36b9-438d-8b26-23fa96509413.jpg&quot;},{&quot;ImagePath&quot;:&quot;bdf0a07d-f20c-4999-a044-43f7111338dd.jpg&quot;},{&quot;ImagePath&quot;:&quot;51aa8f86-b352-47ea-a835-8a90f5833db2.jpg&quot;},{&quot;ImagePath&quot;:&quot;6aabe090-5e78-4751-ac79-9f37a65dd776.jpg&quot;}];


now, I did a replace on &quot; to a random string (I used moo) and it didnt work, but when i did a replace on " it did. So that tells me that I am actually returning a valid Json string.
However, the code just doesn't work.
I can't see the wood for the trees, so any help would be greatly appreciated.

ssystems
01-15-2012, 09:22 AM
Please take a look at the JSonSerializer