0
votes

I have Post Method

[HttpPost]
public HttpResponseMessage Post(MemberViewModel model)

Another Post Method in same Controller. I add the attribute routing in login method

[Route("api/members/login")]
[HttpPost]
public HttpResponseMessage Login([FromBody]LoginViewModel model)
{}

public class LoginViewModel
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

The default post method is working fine but when I call Login Post Method the model (LoginViewModel is always null). I used fiddler to do the testing.

Fiddler

POST http://localhost:49595/api/members/login/ Http/1.1

User-Agent: Fiddler

Content-Type: Application/JSON

Host: localhost:49595

Content-Length: 79

Request Body { “Username”: [email protected], “Password”: “393f83x393” }

It is working fine with one parameter

[Route("api/members/login")]
[HttpPost]
public HttpResponseMessage Login([FromBody]string userName)
{}

Kindly advice what wrong with Model

Thanks.

1

1 Answers

0
votes

Your Fiddler shows this line:

Request Body { “Username”: [email protected], “Password”: “393f83x393” }

That's not valid JSON. The email account should be enclosed in single or double quotes.