I have a .cshtml page which builds an array of data which looks like this in the console.log:
JSON.stringify(obj) = [{"ParcelKey":8911,"ParcelStatus":"Check"},{"ParcelKey":8912,"ParcelStatus":"Check"}]
I have Ajax code which looks like this:
$.ajax(
{
type: "POST", //HTTP POST Method
url: "/Parcel/BulkParcelStatusUpdateSave", // Controller/Action
data: JSON.stringify(obj),
traditional: false,
cache: false,
contentType: "application/json; charset=utf-8",
success: function (data) {
const myArray = data.split("|")
$('#Parcel_Save_Success').removeClass('hidden');
$('#CaseStatus').val(myArray[0]);
$("#DetailedParcelGrid").data("kendoGrid").dataSource.read();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error While Saving Parcel Details. Status: " + textStatus); alert("Error: " + errorThrown);
}
});
I have a model which looks like this:
public class ParcelBulkUpdateSaveModel
{
public int ParcelKey { get; set; }
public string ParcelStatus { get; set; }
}
And in the ParcelController, I have the following:
[HttpPost]
public string BuldParcelStatusUpdateSave(List<ParcelBulkUpdateSaveModel> sentData)
{
string returnString = "";
foreach (var record in sentData)
{
_repo.BulkParcelStatusUpdateSave(record);
}
return returnString;
}
I have a breakpoint set on the foreach statement in the controller.
When I run the application, the Ajax executes the error and I get the 2 alerts.
Why is the Ajax call not able to connect to the controller?
Thanks for any assistance.
>Solution :
You have a typo.
Your calling BulkParcelStatusUpdateSave
when the function is BuldParcelStatusUpdateSave