I can't figure out why the below calls to my "GetBatch" webapi method isn't working. I am not sure if I need to specify the route, etc. I do have other HttpPost methods but note that I am specifically trying to call the method I defined below.
What can I do to fix? The URL should be correct because different actions do get called. Thank you for your time.
JavaScript:
var accountGetBatchURL = '@HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)@Url.Content("~/")api/Account/GetBatch'; function () { 'use strict'; var lastColumns = oTable.context[0].aoColumns; var lastSearch = oTable.context[0].aoPreSearchCols; var suppliedSearchParameters = new Array(); for (var i = 0; i < lastSearch.length; ++i) { if (lastSearch[i].sSearch !== "") { suppliedSearchParameters.push({ "column": lastColumns[i].mData, "value": lastSearch[i].sSearch }); } } var dataToSend = { 'searchParameters': suppliedSearchParameters };$.ajax({ url: accountGetBatchURL, type: 'POST', cache: false, contentType: 'application/json', dataType: 'json', data: JSON.stringify(dataToSend), error: function (jqXHR, textStatus, errorThrown) { bootbox.alert("There was a problem with sending the search parameters to the service for processing. Extended information: Error Number: " + textStatus + " Error Thrown: " + errorThrown); }, success: function (json) { bootbox.alert("Successfully sent search parameters to LMS Search service!") } }); }
C# Model Code:
public class AccountSearchDTO { public AccountSearchParameterDTO[] searchParameters { get; set; } } public class AccountSearchParameterDTO { public string column { get; set; } public string value { get; set; } } public class AccountSearchResultsDTO { public int numOfRows { get; set; } }
C# Account Controller Code:
[HttpPost] public AccountSearchResultsDTO GetBatch([FromBody] AccountSearchDTO param) { AccountSearchResultsDTO results = new AccountSearchResultsDTO(); results.numOfRows = 0; return results; }