Serialize datatable as JSON

C# Part:

JQuery Part:


using Newtonsoft.Json;




[HttpPost]


public JsonResult GetDatatableAsJson(String currentdate, String cmpositionid)


{


DataTable dt = new DataTable();


//


//Fill datatable as require


//


String SerializedDatatable = JsonConvert.SerializeObject(dt, Formatting.None);


return Json(SerializedDatatable, JsonRequestBehavior.AllowGet);


}



$(function () {


$.ajax({


type: "POST",


url: "CMSupervisor/DateCmSpecificOutletMapData",


async: true,


contentType: "application/json; charset=utf-8",


data: "{'currentdate':'" + currentdate + "','cmpositionid':'" + cmpositionid + "'}",


dataType: 'json',


success: function (data) {


var parsed = JSON.parse(data);


//Looping the Datatable


parsed.forEach(function (row) {


//access the column name


var value = row.ColumnName;


});


}


});


});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s