I have a datatable
values converted to json
which is passed to the client side. Now i have to make a loop of the result and add it to an array
.
//Code:
public string GetColumns()
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Rows.Add("Id");
dt.Rows.Add("First Name");
dt.Rows.Add("Last Name");
dt.Rows.Add("Mobile Number");
dt.Rows.Add("Email");
return JsonConvert.SerializeObject(dt);
}
//ClientCode:
var colHeader = [];
$.ajax({
url: '@(Url.Action("GetColumns", "Default"))',
//url: 'Home/GetColumns',
datatype: 'json',
mtype: 'GET',
success: OnComplete,
error: OnFail
});
function OnComplete(result) {
alert(result);
$.each(result, function () {
colHeader.push(this.Name);
});
}
function OnFail(result) {
alert('Failed');
}
I'm getting the value inside the OnComplete
function. Not sure how to loop and add it into an array colHeader
.
Note: This is basically to bind the header of jqGrid
dynamically.