I am posting JSON to my controller, but the problem is I am getting the correct count in list. i.e if JSON has two elements list has count of two but null data. Following is the code via I am making and sending the JSON. I've use TabletoJSON for making the JSON.
$('#productsObj').click(function () {
var rawMaterials = $('#productsTable').tableToJSON(
{
ignoreColumns: [3]
});
alert(JSON.stringify(rawMaterials));
console.log(rawMaterials);
$.ajax({
url: "/Supplies/insertRawMaterial",
type: "POST",
data: JSON.stringify(rawMaterials),
contentType: "application/json; charset=utf-8",
dataType: "json",
traditional: true,
error: function (response) {
alert(response.responseText);
},
success: function (response) {
alert(data);
alert(response);
}
});
});
Following is the controller action method which is receiving data.
public ActionResult insertRawMaterial(List<String> data)
{
if (data != null)
{
return Json("Success");
}
else
{
return Json("An Error Has occoured");
}
}
I am not sure where I am doing it wrong. Following is the JSON in alert.
[{"Raw Material Name":"Asphalt","Short Code":"AS02","Price":"20"}]