Reputation: 2720
I have an ASP.NET Core 6.0 Web API and want to call a GET
method using ajax.
This is my Ajax call:
$.ajax({
type: "GET",
url: "/api/CountriesApi/GetById?id=" + id,
success: function (result) {
...
}
}
});
And here is my action method in the API:
[HttpGet("{id}")]
public IActionResult GetById(int id)
{
...
}
My problem is that the parameter value is zero and I can't send id
value to the action method.
Upvotes: 0
Views: 752
Reputation: 681
Make sure you pass proper integer value in your id parameter in the ajax call, Otherwise the .net code should work. If you are using default name from param you can opt-out the {id} also
[HttpGet]
public IActionResult GetById(int id)
{
...
}
Upvotes: 1