I read here a few topics on how to get property values from an object.
In my case, I have something in the controller:
[HttpPost]
public ActionResult GetSomething() {
return Json( new {
data = AModel.Get()
}, JsonRequestBehavior.AllowGet );
}
In the model:
public static List<Hashtable> Get() {
List<Hashtable> list = new List<Hashtable>( 0 );
Hashtable table = new Hashtable();
table.Add( "ITEM_1", "Value1" );
table.Add( "ITEM_2", "Value 32" );
list.Add( table );
table = new Hashtable();
table.Add( "ITEM_1", "Value22" );
table.Add( "ITEM_2", "Other" );
list.Add( table );
return list;
}
And in Javascript:
var test;
$.ajax({
type: "post",
url: "Action/Controller",
data: {},
dataType: "json",
async: false,
success: function (data) {
test = data.data;
},
complete: function () {
console.log(test);
});
I got the console, as in the following image:

I want to get the property value ITEM_1and the results for me: Value1, Value22.
I tried using
for(var key in test) {
console.log(test[key].ITEM_1);
//console.log(test[key].ITEM1);
}
but it does not work.
Of course, I renamed the key ITEM_1to ITEM1(in the model), but the same result: undefinedbut in the console I see the values for the whole object.

Help me please.
source
share