In my controller's action method, I am storing data in view data like the below:
int[] numbers = new int[] {10, 20, 30, 40};
ViewData["Numbers"] =numbers;
now in my view, from jQuery trying to get data into array. I've tried like below:
<script type="text/javascript">
var tempArray = ['@ViewData["Numbers"]'];
</script>
but when I loop throw the tempArray, it is printing values like below:
Index Value
0 int[]
for value instead of printing 10, printing some array. My question is How to retrieve array from view data in jQuery?
Thanks in advance
@ViewData["Numbers"]without the single quotes and []? That could give you want you're looking for as when the rendering engine processes it, it would put the contents of that string into the right side of that setter. It looks like because it's surrounded by the [] it's putting your array into the first position of an outside array.