This might be basic question but I couldn\'t find where the issue is. I am using .Net Core for by back end and angularJS for front end. below is my code.
<Just Change your
data: { email: scope.email, password: scope.password },
to
data: { "email": scope.email, "password": scope.password },
You must create an Class or Interface to send several parameters
public class PostParams
{
public string email { get; set; }
public string password { get; set; }
}
[HttpPost]
public JsonResult loginInfo(PostParams params)
{
//do something here
}
You have to use the [FromBody]
attribute with a model parameter.
public class Credentials
{
public string Email { get; set; }
public string Password { get; set; }
}
public IActionResult Login([FromBody]Credentials creds)
{
// do stuff
}
This is because in ASP.NET Core MVC the default content type is application/x-www-form-urlencoded
(for handling HTML form data). The [FromBody]
attribute tells the model binder to instead try and create the model from JSON content.