Receiving null value in POST param

Viewed 1984

I receive a null value always in web api rest post request to a controller

In my controller

[HttpPost]
public HttpResponseMessage PostCustomer([FromBody]Customer customer)
{

       System.Diagnostics.Debug.WriteLine(customer); #CustomerApp.Models.Customer
       System.Diagnostics.Debug.WriteLine(customer.FirstName); #null

}

Model

public class Customer
{
    public int Id { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
}

Request:

POST: http://localhost:21894/api/customer/postcustomer

Content-Type: application/json

body: {FirstName: "xxxx", LastName: 'yyyy'}

I tried the following solutions but nothing works out

https://myadventuresincoding.wordpress.com/2012/06/19/c-supporting-textplain-in-an-mvc-4-rc-web-api-application/

How to get POST data in WebAPI?

Can anybody guide me with help or the correct link

Answer: Made a curl request instead of dealing with postman as like this gave me the solution

$ curl -H "Content-Type: application/json" -X POST -d '{"FirstName":"Jefferson","LastName":"sampaul"}' http://localhost
:21894/api/customer/postcustomer
2 Answers
Related