I'm trying to call API controller method using ajax and passing some parameters. The api method is getting called but values are coming as null in controller method.
Using same ajax call, another controller (not api controller) having same method receives parameter values and returns results but i'm stuck with passing values to api controller method. Kindly help
$(document).ready(function ()
{
$("#DropDownName").change(function ()
{
$.ajax({
type: "POST",
dataType: "text",
url: "@(Url.Action("SampleAction", "XYZController"))",
data: {
"param1": $("#DropDownName :selected").val(),
"param2": $("#input2").val(),
"param3": $("#input3").val()
},
success: function (response) {
document.getElementById("result").textContent = "Result: " + response;
},
});
});
});
API Controller Method
[Route("api/[controller]")]
[ApiController]
public class XYZController : ControllerBase
{
[ActionName("SampleAction")]
[HttpPost]
public decimal SampleAction(string dropdownselectedvalue,decimal input2, int input3)
{
//code here - This method is getting called but getting null parameter values
}
}