I have 2 asp.net web api actions in an ApiController-subclassed controller. The 2 action methods are POST. One method is working with non-null request body. But the other action method always get null request body. I do not know the reason why the second POST action does not work. Please help.
The following POST action method works OK with non-null request body binding: parameter "model" in method signature is bound correctly.
[HttpPost]
[Route("create/{sessionid:guid}")]
public HttpResponseMessage CreateAccount(Guid sessionid, UserAccountDto model)
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
return Request.CreateResponse(HttpStatusCode.OK, model);
}
Dto class:
public class UserAccountDto
{
public long? AccountId { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Salt { get; set; }
public string PlainTextPassword { get; set; }
}
Call with API by using Advanced Rest Client tool plugged in Chrome
POST http://localhost:55540/guests/create/13DD8111-8A00-48CE-997F-28EE3C88895D
{
email:"meme@me.com",
password:"fkdld",
salt:"salt",
plaintextpassword :"abc"
}
However, the 2nd ApiController POST action method does not work. Parameter "model" in method action is always null; it is not bound correctly for some reason.
[HttpPost]
[Route("convert/{sessionid:guid}")]
public IHttpActionResult ConvertAccount(Guid sessionid, LinkedAccountThinDto model)
{
var accountType = model.AccountType;
var accountKey = model.AccountKey;
return Ok();
}
Custom Dto class:
public class LinkedAccountThinDto
{
public string AccountType { get; set; }
public string AccountKey { get; set; }
}
Call with API by using Advanced Rest Client tool plugged in Chrome:
POST http://localhost:55540/guests/convert/13DD8111-8A00-48CE-997F-28EE3C88895D
{
accounttype: “abcdf”,
accountkey: “1234567”
}