Here is the scenario involving an ajax call:
...
$("#testBtn").click(function (e) {
e.preventDefault();
$.ajax({
url: "/profile/GuestList",
data: {"keytype": "1"},
method: "POST",
contentType: "application/json",
success: function (data) {
...
}
});
});
...
This interacts with the following controller method:
[HttpPost]
public async Task<IActionResult> GuestList([FromBody]string keytype)
{
try
{
return Ok();
}
catch (Exception ex)
{
}
}
The objective was initially to send an enum type, but that approach did not work. We then attempted to send an integer with a value of 1
, only to receive 0 instead. Adding [FromBody]
did not change this outcome. As a final attempt, we switched to sending a string and are now experiencing issues where the value received is null.
Where do you think the issue lies across all these variations?