I have an API controller which has actions to get and post data. and I am trying to access GetProductById meyhod from ajax bu productId parameter is always equals to zero (0). When I want to call GetAll method with GET method everything is fine. JavaScript code is like below
var product = JSON.stringify({ productId: id });
$http({
method: 'POST',
contentType: 'application/json',
url: '/api/Product/ProductInfo',
data: product
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log(response);
});
And API Controller is like below
[Route("api/Product")]
public class ProductController : BaseController
{
[HttpPost]
[Route("ProductInfo")]
public Product GetProductById([FromBody]int productId)
{
return UnitOfWork.GetRepository<Product>().FirstOrDefault(i => i.Id == productId);
}
[HttpGet]
[Route("GetAll")]
public string GetAll()
{
return "Can";
}
}
Can anyone say why that case is happening?