c# - Datetime throwing model state is invalid for date posted to Web API (EF Backed) -
this error getting submissions follow specific "pattern" per logging
2016-01-21 01:05:01.5879 error model state invalid, throw bad request. model state: { "tbl_externalcontacts.last_password_change": { "value": null, "errors": [ { "exception": null, "errormessage": "the value '19/05/2009 15:17:35' not valid last_password_change." } ] } }
i'm submitting numerous things api , it's occurring when first value in date goes on 12. should point out i'm in uk, our date format dd/mm/yyyy.
how tell asp.net validate dates sent in model in format valid processed?
example:
public static void main() { string[] datevalues = { "30-12-2011", "12-30-2011", "30-12-11", "12-30-11" }; string pattern = "mm-dd-yy"; datetime parseddate; foreach (var datevalue in datevalues) { if (datetime.tryparseexact(datevalue, pattern, null, datetimestyles.none, out parseddate)) console.writeline("converted '{0}' {1:d}.", datevalue, parseddate); else console.writeline("unable convert '{0}' date , time.", datevalue); } }
source: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
Comments
Post a Comment