if i type "controler/action" data in url send corectly,but when want to send, data to api data data send zero to method parameter
var urll = 'https://localhost:44337/api/apiialbums/GetAlbum';
$.ajax({
type: "post",
url: urll, error: function () { alert("errore") },
data:{id:25,x:2},
success: function (dataa) {
alert("okk");
}
})
my api class code:
[HttpPost]
public async Task<ActionResult<Album>> GetAlbum(int id,int x)
{
var album = await _context.Albums.FindAsync(id);
if (album == null)
{
return NotFound();
}
return album;
}
What I have tried:
i can send data in url and dont use data:{id:25,x:2} that
in this case id,x send corectly.
var urll = 'https://localhost:44337/api/apiialbums/GetAlbum?id=25&x=3';
$.ajax({
type: "post",
url: urll, error: function () { alert("errore") },
success: function (dataa) {
alert("okk");
}
})
and in my ipa method use [httppost]
[HttpPost]
public async Task<ActionResult<Album>> GetAlbum(int id,int x)
{
var album = await _context.Albums.FindAsync(id);
if (album == null)
{
return NotFound();
}
return album;
}
how to use data:{id:25,x:2} instead of send data in url?