Single Parameter passed to Core Controller always null

  • Thread starter Thread starter zBestDataLLC
  • Start date Start date
Z

zBestDataLLC

Guest
Ask Question
up vote 0 down vote favorite

I am upgrading mvc application to .Net Core and am having difficulty passing a string value via ajax to the controller. I have tried various solutions I found on the web ([FormBody], prefixing with "=", and some others), but no luck. The value is always null. If I change it to GET, it works. What has changed in Core that I need to fix?

Thanks!

var result = "";
$.ajax({
url: "/system/loadchildrenaccounts/",
type: "POST",
data: JSON.stringify({ "parentID": "12345" }),
contentType: 'application/json; charset=utf-8',
success: function (data) {
result = data;
},
done: function (data) {
result = data;
},
fail: function (data) {
result = data;
},
error: function (jqXHR, textStatus, errorThrown) {
//alert('request failed :' + errorThrown);
}
});





[HttpPost]
public string LoadChildrenAccounts(string parentID)
{
using (zBestContext db = new zBestContext())
{
List<Generic> s = db.Accounts.Where(a => a.ParentAccountID == parentID)
.Select(a => new Generic { LabelOrID = a.AccountID, Description = a.Company })
.OrderBy(a => a.Description)
.ToList();

Generic item = new Generic();
item.LabelOrID = "";
item.Description = "*** Company ***";
s.Insert(0, item);

return s.toJSON();
}
}

Continue reading...
 
Back
Top