I am using dot net core Web API. I have a controller HomeController.cs
using Microsoft.AspNetCore.Mvc;
using WebAPI.Models;
namespace WebAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class HomeController : Controller
{
[HttpPost]
public IActionResult Index(User user)
{
return Ok(user);
}
}
}
The model user is as follows
namespace WebAPI.Models
{
public class User
{
public string username { get; set; }
public string password { get; set; }
}
}
When I run the following jquery code from the front end I get an error 415 (Unsupported Media Type)
$.ajax({
type: "POST",
url: "https://localhost:7137/Home",
data: { username: "username" , password: "password"},
success: function(data){console.log(data)},
dataType: "application/json"
});
I am not getting what mistake I am doing.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/3e0jQV7
Comments
Post a Comment