Reputation: 48
I am in creation of webapi odata service. I have a post method named "Validate" in my controller named "User" as below:
public class UserController : ODataController
{
[HttpPost]
public HttpResponseMessage Post(LoginEntityDto objLogin)
{
//mylogin
}
}
//Custom class
public class LoginEntityDto
{
public string username { get; set; }
public string password { get; set; }
}
I am inputting this post method with the below JSON Format
{
"username": "C201566",
"password" : "pwd"
}
I am using the content-type : application / json
but in my post method the input objLogin is always null Please help me in resolving this issue.
Upvotes: 0
Views: 1561
Reputation: 2132
OData/Webapi doesn't support post a complex type in this way, why not make it as an entity type by define the key and entityset.
[key]
username {get;set;}
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<LoginEntityDto>("LoginEntityDto");
or you can use action to post this complex type as parameter. FYI: http://odata.github.io/WebApi/#04-07-action-parameter-support
Upvotes: 1