c# - Validation errors texts don't appear -
i have class 2 properties
[stringlength(8, errormessage = "user name can't longer 8 chars!")] [required(errormessage = "must filled!")] public string nickname { get; set; } [required(errormessage = "must filled!")] [datatype(datatype.password)] public string password { get; set; }
and have partial view, user inserts details , presses sumbit button.
nickname: @html.textboxfor(x => x.nickname) @html.validationmessagefor(x => x.nickname) </div> <div> password: @html.textboxfor(x => x.password) @html.validationmessagefor(x => x.password) </div> <button type="submit">log in</button>
this post action,
[httppost] public actionresult login(shortuser u) { if (modelstate.isvalid == true) { if (u.passmatchuser()) { formsauthentication.setauthcookie(u.nickname, true); } else { modelstate.addmodelerror("error","username / password inncorect!"); } return redirect(controllercontext.httpcontext.request.urlreferrer.tostring()); } else { return redirect(controllercontext.httpcontext.request.urlreferrer.tostring()); } }
if insert invalid values validation texts don't appear.
you need set validation summary on
@html.validationsummary(true) @html.enableclientvalidation()
on partial view.
wiki
Comments
Post a Comment