Ajax post parameter always NULL in MVC controller
I have a MVC project, which uses .Net Core.
In one of the shared layout, I have the javascript:
var requestData = { term:"myReport" };
var myData = JSON.stringify(requestData);
$.ajax({
url: '@Url.Action("ReportErrorData", "OperationReport")',
type: 'POST',
data: myData,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function (xhr) {
alert('Error: ' + xhr.statusText);
},
success: function (result) {
$('#divError2').text(result);
}
});
});
In the controller, I have
public ActionResult ReportErrorData(string term)
{
var error = string.Empty;
try
{
....
}
catch (Exception ex)
{
.....
error = ex.ToString();
}
....
var r = new JsonResult(error);
return r;
}
For some reasons, when it reaches the controller, the variable term is always null. However, if I use developer tool, I can see the request body is:
{'term':'myReport'}
I did the same thing in MVC4 project, and it worked fine. Could this because of .Net Core?
Thanks