json - .NET WebAPI not parsing [FromBody] properly from request content -


i'm used flow of http content negotiation seems out of place following:

i have .net webapi controller following content:

    /// <summary>     /// search records corresponding given criterias     /// </summary>     [acceptverbs("post")]     public async task<ihttpactionresult> searchrecord([frombody]searchpeoplemodel recordsearchmodel)     {         var recordservice = context.services.get<irecordservice>();         var result = await recordservice.searchrecord(recordsearchmodel);         return jsonify(result);     } 

using fiddler, request content follow:

post http://localhost:43465/api/record/searchrecord http/1.1 host: localhost:43465 connection: keep-alive content-length: 72 pragma: no-cache cache-control: no-cache accept: application/json origin: (hidden) user-agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36  (khtml, gecko) chrome/60.0.3112.101 safari/537.36 content-type: application/json referer: http://localhost:43465/ accept-encoding: gzip, deflate, br accept-language: fr-fr,fr;q=0.8,en-us;q=0.6,en;q=0.4 cookie: asp.net_sessionid=(hidden)  {"any":"mat","firstname":"","lastname":"","birthname":"","patientid":""} 

the resulting recordsearchmodel null when debugging webapi. i've tried play body content , json.stringify/not , not appear problem either.

i must missing but... can't see ! hope can !

edit: request here searchpeoplemodel class. won't show implementation of recordservice has nothing question here.

public class searchpeoplemodel {     public string {get; set;}     public string firstname { get; set; }     public string lastname { get; set; }     public string birthname { get; set; }     public datetime? birthdate { get; set; }     public guid? patientid { get; set; } } 

some precision may have been unclear: recordsearchmodel null when asp.net web api receives request, rest of code acts intended.

i dig out.

it appears parameter

public guid? patientid { get; set; } 

from searchpeoplemodel cannot deserialized default asp.net webapi. such behavior work must send:

{"any":"mat","firstname":"","lastname":"","birthname":""} 

instead of:

{"any":"mat","firstname":"","lastname":"","birthname":"","patientid":""} 

cause: "" cannot bu turned valid null guid. "[some-valid-guid]" works though.

hope can someone.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -