I know this question may have been asked hundreds of times and that there is tons of examples about and probably I may be downvoted, but I have to ask it any way because I don't know in what side (controller, script or both) my code is incorrect and also b/c I couldn't find an example on how to cast an object into a two-dimensional array (which is what I believe the result is): I need to pass a List> from the MVC controller back to the ajax script, then manipulate the array results, but I don't know how to cast the array to read its elements.
[HttpGet]
public ActionResult ListBoxCustomize(string listName)
{
var result = new List<KeyValuePair<string, string>>(); // Key , Value
// Code to add items to the list
.........
return Json(new { items = result }, JsonRequestBehavior.AllowGet);
}
JScript
$.ajax(
{
success: function (data) // THIS IS WHAT IS RETURNED -> data = Object {items: Array[5]}
{
alert( items[0][0] ) // Reference Error: items is not defined
OR
alert( data[0][0] ) // Uncaught TypeError: Cannot read property "0" of undefined
.... and so it goes with all other cast and combinations that I've tried.
}
data.items[0][0]instead ofitems[0][0]?