c# - Post request to API is receiving NULL -
i have asp.net core api expecting post request in shape of particular object -- see code sample below.
i make sure front-end client sends data in exact shape. make sure inspecting call fiddler data being sent api.
when request hits api method though, it's null
.
my first thought model binder cause of issue. meaning, somehow, data i'm sending not matching object api method expecting.
i've been staring @ code few hours , seems ok me. assuming shape of object sent front-end matches object api expecting, else causing issue?
i've been using similar code on app , working fine.
my code looks this:
[httppost("test")] public async task<iactionresult> dosomething([frombody]myobject data) { // logic here... }
here few things i'm sure about:
- i'm hitting api method there no routing issues
- the point above confirms front-end client sending request
- i know front-end client sending data -- confirmed through fiddler
update:
this caused model binder. changed code myobject
dynamic
see happen , sure enough i'm getting data sent front-end. haven't found exact property that's causing issue yet i'm close. here's api method looks till find exact cause of issue:
[httppost("test")] public async task<iactionresult> dosomething([frombody]dynamic data) { // logic here... }
update 2: found issue!!!!
i had guid
property null
valud in , model binder didn't it.
this happens when object can't deserialized json request.
the best practice make sure request properties can accept null
values (make value types properties nullable). , can validate action needs provided in request , return 400 error if not.
Comments
Post a Comment