1

Here is my Model

    public class Country
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Abbreviation { get; set; }

}

Here is my controller

 [Route("api/[controller]")]
public class TestController : Controller
{
    public TestController()
    {

    }


[HttpPost]
 public IActionResult Create([FromBody] Country country)
    {
            return StatusCode(500, "");
    }

}

When i test my controller through PostMan using following data, why country object is always null. Here is the data i am sending through postman. My break point is hitting that means API is running fine, its just that i am not getting my data there.

I selected "raw" and JSON("application/json") on POSTMAN to send following data

{
     "id": "1",
     "name": "ddd",
     "abbreviation": "ate"
}

1 Answer 1

2

Id is a GUID but you are passing it an Integer you have two options either change id to an integer like:

public class Country
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Abbreviation { get; set; }
}

or pass a GUID via postman.

{
 "id": "593d7c22-893c-474f-9df8-00e219074cb8",
 "name": "ddd",
 "abbreviation": "ate"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked. I thought it should atleast fill in other fields, but seems it is ignoring everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.