Jeremy Miller Jeremy Miller - 1 year ago 197
C# Question

Postman Testing send string to Web Api accepting string is null

I have been testing all the Get,Create,Update methods with Postman in which the Get passes in nothing. The Create and Update passes in raw json with Activity object with several properties that do match up with the C# class

So this signature for Create and Update works fine

public IHttpActionResult UpdateActivity(Activity activity)

Above works with Postman passing in JSON content type with all the properties. I have done this on OTHER projects.


I'm trying to simply pass in a string and it is null no matter what

public IHttpActionResult DeleteActivity([FromBody]string Id)
// delete
var del = ActivityService.DeleteActivity(Id);
return Ok(del);

Postman I tried MANY ways


I have tried MANY many ways based on blogs and google search one such example

{ "Id" = "5808786fa3e9ec79546b3c71" }

Answer Source

For Postman --> Web Api ... You will want to drop [FromBody] when passing in string as json format. I have had this problem in the past.

So others are correct that you DO want this line in Postman

{ "Id" : "5808786fa3e9ec79546b3c71" } 

However, you WILL be getting null still as you need to change from

public IHttpActionResult DeleteActivity([FromBody]string Id)


public IHttpActionResult DeleteActivity(string Id)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download