I'd like to pass an AJAX parameter to the MVC Controller in ASP .Net Core 2.
This is what i tried :
function getMatchesFromChampionshipAsync(championship) {
console.log(championship);
$.ajax({
url: "/Bets/Matches",
type: "POST",
data: { "championship": championship },
dataType: 'json',
contentType: 'application/json; charset=UTF-8',
success: function (response) {
alert(response)
}
})
}
I'm sure that the parameter championship
is correct (I also tried to log it), but the Controller always receives null
.
This is the Controller Action Method code:
[HttpPost]
public IActionResult Matches([FromBody] string championship) {
return Json(championship);
}
The browser also alerts null
.
I also read other questions about it but no one worked.