0

I'm trying to post to Web Api Values controller via post:

// POST api/values
public void Post([FromBody]string value)
{
}

but the value is always null.

I'm using Postman to post this in body: {"test"} set as Json(application/json)

asked Apr 13, 2017 at 19:36
4
  • What you are posting is not valid JSON. What it should be is {"value":"hello world"} Commented Apr 13, 2017 at 19:38
  • what if it is a serialized json string? does it always have to be "value: ? Commented Apr 13, 2017 at 19:39
  • No you need to create a new class which contains the properties you need and then use that as the input parameter for your "Post" Method. FromBody is really only the basic way to get simple properties - Its much easier to bind a model/class. Commented Apr 13, 2017 at 19:43
  • {"value":"hello world"} still doesn't work Commented Apr 13, 2017 at 19:55

1 Answer 1

1

Sending simply "test" in quotes did the trick.

answered Apr 13, 2017 at 20:26
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.