Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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”
}
Posted

1 solution

Try request format in below form:
{
"accounttype": "abcdf",
"accountkey": "1234567"
}

Add quotes to key name.
 
Share this answer
 
v2
Comments
Thomas Benz 12-Mar-15 12:27pm    
@nagendrathecoder. I tried to use quotes, but the problem was not solved. The problem happens for both testing Chrome-plugged-in tools I am using POSTMAN and Advanced Rest Client

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900