FromBody value get null
16,922
Solution 1
The POST body payload in Fiddler should be:
=foo_bar
instead of:
value=foo_bar
That's just one of those strange things about the model binding in the Web API. If you want to support value=foo_bar
in the POST body payload you could always write a view model:
public class MyViewModel
{
public string Value { get; set; }
}
and then have your method take this view model as parameter:
public void Post(MyViewModel model)
{
... work with model.Value here as usual
}
Solution 2
I meet this issue, and the solution is:
to fit the Request Body format =foo_bar,
also need Request haders:
Content-Type: application/x-www-form-urlencoded
Author by
Hakan Ertuğ
Updated on July 27, 2022Comments
-
Hakan Ertuğ almost 2 years
This is Asp.Net Webform application
This is my POST method in my Apicontrollerpublic void Post([FromBody]string value) { }
I'm with fiddler post process.
I did so experiment.
But it did not.What is the problem.
Can you help?I've tried it, I've failed.
public void Post(MyViewModel model) { string aa = model.Value; } public class MyViewModel { public string Value { get; set; } }
In Fiddler:
Request Body: Value=hakan
-
Hakan Ertuğ almost 11 yearsEdited my question. Can you check?
-
Darin Dimitrov almost 11 yearsDid you set the
Content-Type
request header toapplication/x-www-form-urlencoded
in Fiddler? -
Hakan Ertuğ almost 11 years:):):) I am grateful to you. Thank you very, very much. its working.
-
Jon Onstott almost 11 yearsI was having the same problem with a Windows Java program (using Scala and Dispatch). This answer solved it for me also.
-
Paul George over 9 yearsThanks - adding "Content-Type: application/x-www-form-urlencoded" worked for me.
-
ANJYR over 8 yearsThanks @DarinDimitrov after changed of Content-Type application/x-www-form-urlencoded" it's worked..