c# - ModelState.IsValid is always false because of datetime.now -


i have asp.net mvc application , in edit , create actions set date field of class datetime.now. works fine , can add , edit records. when want delete records modelstata.isvalid false , error "the value '4/25/2015 9:34:39 am' not valid register time." register time display name of field.

here actions code:

public actionresult create([datasourcerequest]datasourcerequest request, invtgroups invtgroup) {     if (invtgroup != null && modelstate.isvalid)     {         invtgroup.ddate = datetime.now;         repo.insert(invtgroup);     }     return json(new[] { invtgroup }.todatasourceresult(request, modelstate)); } [httppost] public actionresult delete([datasourcerequest]datasourcerequest request, invtgroups invtgroup) {     if (invtgroup != null && modelstate.isvalid)         repo.delete(invtgroup);     return json(new[] { invtgroup }.todatasourceresult(request, modelstate)); } 

this model (i'm using entity framework code first):

public class invtgroups : user {     [key]     [column(typename = "varchar"), stringlength(21)]     public string cgroupcode { get; set; }      [column(typename = "varchar"), stringlength(50)]     public string cgroupname { get; set; }      [column(typename = "bigint")]     public int64? licode1 { get; set; }      [column(typename = "bigint")]     public int64? licode2 { get; set; }      [column(typename = "bigint")]     public int64? licode3 { get; set; }      [column(typename = "bigint")]     public int64? licode4 { get; set; }      [column(typename = "bigint")]     public int64? licode5 { get; set; } } 

and user class:

public class user {     [column(typename = "varchar"), stringlength(20)]     public string cuserno { get; set; }      [column(typename = "datetime")]     public datetime? ddate { get; set; } } 

you can following:

1- _layout.cshtml

 <script>         kendo.culture("en-gb");         var culture = kendo.culture();         culture.calendar.patterns.d = "dd mmm yyyy"; // 25 feb 2015         culture.calendar.patterns.d = "dd mmm yyyy";         culture.calendar.patterns.t = "hh:mm";   // 16:45         culture.calendar.patterns.t = "hh:mm";         culture.calendar.patterns.g = "dd mmm yyyy hh:mm";         culture.calendar.patterns.g = "dd mmm yyyy hh:mm";  </script> 

2- global.asax

   protected void application_beginrequest(object sender, eventargs e)         {              cultureinfo info = new cultureinfo("en-gb");             info.datetimeformat.shortdatepattern = "dd mmm yyyy";             info.datetimeformat.longdatepattern = "dd mmm yyyy hh:mm";             info.numberformat.currencydecimaldigits = 2;             info.numberformat.currencygroupseparator = ",";             info.numberformat.numberdecimaldigits = 2;             thread.currentthread.currentculture = info;             thread.currentthread.currentuiculture = info;         } 

the above code setup date format , number formatting whole application

3- can read more information how add culture js files

hope , if still have question, go ahead.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -