Madhav Sharma

Madhav Sharma

  • 766
  • 899
  • 39.3k

Facing issue in Ajax call

May 5 2020 9:46 AM
Facing issue in Ajax call 
I am passing the array in ajax call but url does not hit on controller why it is happening can some one help
 
// 
$(document).on('click', '#btnUpdate', function () {
var arr = new Array();
var table = $("table tbody");
table.find('tr').each(function (i) {
var obj = {};
//obj.tds = $(this).find('td');
debugger;
obj.FranchiseId = $('select#franchiseId option:selected').val();
obj.ItemCategoryId = $('select#categoryId option:selected').val();
obj.ItemName = $(this).find('td:eq(0) input').val();
obj.Quantity = $(this).find('td:eq(1) input').val();
obj.SupplyPurchaseValue = $(this).find('td:eq(2) option:selected').text();
//obj.SupplyPurchaseValue = $(this).find('td').eq(2).text();
obj.Remarks = $(this).find('td:eq(3) input').val();
arr.push(obj);
});
var postData = { values: arr };
debugger;
var ServiceUrl = '@Url.Action("UpdateItems","ItemList")';
//var abc = "amit";
$.ajax({
type: 'POST',
url: ServiceUrl,
//data: JSON.stringify({myObj: obj}),
//data: { obj: obj },
//data: { '': obj },
data: postData,
traditional: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (obj) {
debugger;
alert(data);
}
});
});
 
Conrroller Code
 
 
[HttpPost]
public JsonResult UpdateItems(List<ItemUpdateViewModel> data)
{
var res = new JsonMessage();
res = repo_itemlist.SaveAndUpdateItems(data);
//return View(data,);
return Json(res, JsonRequestBehavior.AllowGet);
}
 
 

Answers (6)