i know following not possible, there similar way achieve 1 of 2 properties has filled out? in other words, user has enter either username or email.
public class logonmodel { [required(orfield=email)] [display(name = "user name")] public string username { get; set; } [required(orfield=username)] [display(name = "email")] public string email{ get; set; } [required] [datatype(datatype.password)] [display(name = "password")] public string password { get; set; } [display(name = "remember me?")] public bool rememberme { get; set; } }
you write custom model validation attribute, optionally client-side adapter make javascript validate things, or handle in controller code:
public actionresult logon(logonmodel model) { if(string.isnullorwhitespace(model.username) && string.isnullorwhitespace(model.email)) { modelstate.addmodelerror("username", "either username or email must provided."); } if(modelstate.isvalid) {...} else {...} }
in particular case, more elegant solution may accept either email or username in username
field, , intelligently detect 1 user provided.
Comments
Post a Comment