I have this ajax call and I am passing an array with it that looks like so ["ANC0001-Pin Lot"]
and I am trying to pass it to asp.net. I can see in the network console under 'Request Payload' my array is there.
Here is the jquery:
$.ajax({
type: "POST",
url: "/vendorProject/api/connection/updateVendorItem",
data: JSON.stringify({ edittedItems: editHolder }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('success');
},
failure: function (errMsg) {
alert('failed');
}
});
and here is my ASP.NET Controller:
public List<VendorUpdateClass> updateVendorItem(Array edittedItems)
{
ConnectionClass jobs = new ConnectionClass();
return jobs.updateVendors(edittedItems);
}
updateVendors
method:
public List<VendorUpdateClass> updateVendors(Array items)
{
VendorUpdateCell = new List<VendorUpdateClass>();
VendorUpdateClass vendorUpdatedItem = new VendorUpdateClass();
for (int i = 0; i < items.Length; i++ ){
vendorUpdatedItem.job = "aaa";
vendorUpdatedItem.task = "bbb";
vendorUpdatedItem.vendor = "ccc";
VendorUpdateCell.Add(vendorUpdatedItem);
}
return VendorUpdateCell;
}
I am getting and 500 Internal Server Error:
{
"Message":"An error has occurred.",
"ExceptionMessage":"Object reference not set to an instance of an object.",
"ExceptionType":"System.NullReferenceException",
"StackTrace":" at VendorProject.Models.ConnectionClass.updateVendors(Array items)\r\n
at lambda_method(Closure , Object , Object[] )\r\n
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary 2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\r\n
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\r\n
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\r\n
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
Without the loop this does work. When I put in the loop, this gives me a 500 error. Why is it doing this and how can I fix this?