validation - ASP.NET MVC 4 ModelState.IsValid DateTime false -
i hope can have model
public class users { public virtual int userid { get; set; } [required] [display(name = "user name")] public virtual string username { get; set; } [required] [stringlength(100, errormessage = "the {0} must @ least {2} characters long.", minimumlength = 6)] [datatype(datatype.password)] [display(name = "password")] public virtual string password { get; public virtual datetime lastlogindate { get; set; } public users() { var tmpdate = system.datetime.now; this.lastlogindate = tmpdate; } }
then when either add new user or update existing 1 modelstate.isvalid = false. controller looks like
public actionresult newuser([datasourcerequest] datasourcerequest request, users user) { datetime temp = user.lastlogindate; var errors = modelstate.values.selectmany(v => v.errors); if (modelstate.isvalid)
the value in temp/the model {18/04/2013 10:19:23} error in modelstate "the value '4/18/2013 10:19:08 am' not valid lastlogindate."
i cannot figure out why swapping days , months during isvalid
in web.config have set globalisation
<globalization culture="en-gb" uiculture="en-gb"/>
and machine running on set gb well.
this has not helped. created custom validator date called , returned true still got same error.
any appreciated
thank you
update extract
<table> <tr> <td> <div class="editor-label"> @html.labelfor(model => model.username) </div> <div class="editor-field"> @html.editorfor(model => model.username) @html.validationmessagefor(model => model.username) </div> </td> </tr> <tr id="password"> <td> <div class="editor-label"> @html.labelfor(model => model.password) </div> <div class="editor-field"> @html.editorfor(model => model.password) @html.validationmessagefor(model => model.password) </div> </td> </tr> </table>
Comments
Post a Comment