asp.net mvc - Reading JSON datetime into C# - DateTime not pulling through correctly -


note* know second method has different name 'getconsignmentbystatusid' method pass on 'getexportconsignment' without doing anything.

im getting different datetimes in .net c# class when passed on service mvc application. have searched before i'm unfamiliar json not sure need looking at

here mvc code calls service. 'consignmentsearch' object causing problem. here gets serialized.

public ienumerable<consignmentinfo> loadconsignmentbystatusid(int userid, int companyid, string language, int statusid, int pagenumber, int pagesize, consignmentsearch search)     {         ienumerable<consignmentinfo> consignmentinfo = null;         var serializer = new javascriptserializer();         string jsoninput = serializer.serialize(search);         var content = new stringcontent(jsoninput, encoding.utf8, "application/json");          httpresponsemessage response = client.postasync(             string.format("consignment/getconsignmentbystatusid?userid={0}&companyid={1}&language={2}&pagenumber={3}&numrecs={4}&statusid={5}", userid, companyid, language, pagenumber, pagesize, statusid)             , content).result;          if (response.issuccessstatuscode)         {             consignmentinfo = response.content.readasasync<ienumerable<consignmentinfo>>().result;         }         else         {             throw new exception(response.reasonphrase);         }         return consignmentinfo;     } 

then part of code in service. there 2 datetime fields in object different passed on. need read correct dates? or links appreciated.

public static ienumerable<consignmentinfo> getexportconsignment(int userid, int companyid, string locale, consignmentsearch search, int pagenumber, int numrecs, int statusid)     {          var consignmentstatuslist = new list<consignmentinfo>();         sqldataaccess db = databasefactory.createdatabase(globalsmanager.dbconnectionstring) sqldataaccess;         dbcommand cmd = db.getstoredproccommand("logistics.spgtsconnectgetexportconsignment");          db.addinparameter(cmd, "userid", dbtype.int32, userid);         db.addinparameter(cmd, "companyid", dbtype.int32, companyid);         db.addinparameter(cmd, "locale", dbtype.string, locale);         if (!string.isnullorempty(search.consignmentnumber))         {             db.addinparameter(cmd, "consignmentnumber", dbtype.string, search.consignmentnumber);         }         if (!string.isnullorempty(search.housewaybillnumber))         {             db.addinparameter(cmd, "housebillnumber", dbtype.string, search.housewaybillnumber);         }         if (search.dateofloadingfrom != null)         {             db.addinparameter(cmd, "dateofloadingfrom", dbtype.datetime, search.dateofloadingfrom);         } 

i have found solution , here is

i added following method

 jsonserializersettings microsoftdateformatsettings = new jsonserializersettings         {             dateformathandling = dateformathandling.microsoftdateformat         }; 

and change loadconsignmentbystatusid method this

 public ienumerable<consignmentinfo> loadconsignmentbystatusid(int userid, int companyid, string language, int statusid, int pagenumber, int pagesize, consignmentsearch search)         {             ienumerable<consignmentinfo> consignmentinfo = null;             var content = new stringcontent(jsonconvert.serializeobject(search, microsoftdateformatsettings), encoding.utf8, "application/json"); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -