c# - ASP.Net WebAPI app post data always null for json -


despite of including jsonformatter in global.asax file, post method not parse json data model , showing null.

var jsonformatter = config.formatters.oftype<jsonmediatypeformatter>().first();             jsonformatter.usedatacontractjsonserializer = true; 

i using fiddler post data , below raw request:

post http://localhost:50121/api/store http/1.1 user-agent: fiddler host: localhost:50121 content-type: "application/json" content-length: 84  {”quantity”:"4",“imagepath”:”http://localhost/”,“price”:"20.00"} 

model:

namespace storebackend.models {     public class subcategory     {         public string quantity { get; set; }         public string imagepath { get; set; }         public string price { get; set; }          } } 

the post method is:

public httpresponsemessage post(subcategory products)     {         var database = productsclient.getdatabase("test");         //imongocollection<subcategory> collection = database.getcollection<subcategory>("entities");         //collection.insertone(products);         return new httpresponsemessage() { statuscode = httpstatuscode.accepted };     } 

the products variable of subcategory null. tried using [frombody] attribute still variable null.

can suggest missing? json formatted.

the "double quotes" in json don't right.. try following:

{"quantity":"4","imagepath":"http://localhost/","price":"20.00"} 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -