when i pass array object to controller is not working
when i pass array object to controller is not working
krishnag
Posts: 1Questions: 1Answers: 0
function convertTableToArrayObject() {
var employeeObjects = [];
var table = $('#gridVacationRequest').DataTable();
var data = table.rows().data();
for (var i = 0; i < data.length; i++) {
employeeObjects.push({ "EmployeeIdx": data[i]["EmployeeIdx"] });
}
return employeeObjects;
}
$('#btnvacation').on('click', function (e) {
//var data = artable.$('input, select').serialize();
//e.preventDefault();
//var table = $('#gridVacationRequest').DataTable();
//var data = table.data();
//var data = artable.rows().data();
//var data = artable.rows(['.selected']).data().toArray();
//var json = JSON.stringify(data);
var vacationlst= convertTableToArrayObject();
//alert(JSON.stringify(vacationlst));
//var lstvacmodel = JSON.stringify({ 'lstvacmodel': vacationlst });
var jsonList = JSON.stringify(vacationlst);
var dataToSend = '{"lstvacmodel":' + jsonList + '}';
alert(dataToSend);
//alert(lstvacmodel);
var url = '@Url.Action("GetRequestAmount", "Vacation")';
$.ajax({
type: "POST",
url: url,
dataType: 'json',
contentType: "application/json; charset=utf-8",
//data: JSON.stringify({ lstvacmodel: data }),
data: JSON.stringify({ 'lstvacmodel': vacationlst }), //{ lstvacmodel: JSON.stringify(vacationlst)},
//{ 'lstvacmodel': JSON.stringify(vacationlst) }, //JSON.stringify({ lstvacmodel: vacationlst }),
success: function (result, status, xhr) {
},
error: function (xhr, status, error) {
}
});
});
controller
public JsonResult GetRequestAmount(List<VacationPostModel> lstvacmodel)
{
}
please help me
This discussion has been closed.
Answers
Hi @krishnag ,
"is not working" is a big vague, we need more information to offer any useful advice. We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin