razor - Show only server side errors in validation summary -
i have following view:
@model myproject.models.registerviewmodel <div class="content"> <div class="wrapper"> <h2>e-bill saver registration</h2> <hr /> <div class="columns top-gap"> <div class="first cell width-6 dark-blue-headings"> @using (html.beginform()) { @html.antiforgerytoken() @*@html.validationsummary("", new { @class = "text-danger" })*@ <div class="form-horizontal"> <div class="form-group"> @html.label("account number", htmlattributes: new { @class = "control-label col-md-2 bold" }) <br />@html.validationmessagefor(model => model.accountno, "", new { @class = "text-danger" }) <div class="col-md-10"> @html.editorfor(model => model.accountno, new { htmlattributes = new { @class = "form-control input" } }) </div> </div> <div class="form-group"> @html.label("mpnumber", htmlattributes: new { @class = "control-label col-md-2 bold" }) <br />@html.validationmessagefor(model => model.mpnumber, "", new { @class = "text-danger" }) <div class="col-md-10"> @html.editorfor(model => model.mprn, new { htmlattributes = new { @class = "form-control input" } }) </div> </div> <div class="form-group"> @html.label("email address", htmlattributes: new { @class = "control-label col-md-2 bold" }) <br />@html.validationmessagefor(model => model.email, "", new { @class = "text-danger" }) <div class="col-md-10"> @html.editorfor(model => model.email, new { htmlattributes = new { @class = "form-control input" } }) </div> </div> <div class="form-group"> @html.label("confirm email address", htmlattributes: new { @class = "control-label col-md-2 bold" }) <br />@html.validationmessagefor(model => model.confirmemail, "", new { @class = "text-danger" }) <div class="col-md-10"> @html.editorfor(model => model.confirmemail, new { htmlattributes = new { @class = "form-control input" } }) </div> </div> <div class="form-group"> @html.label("password", htmlattributes: new { @class = "control-label col-md-2 bold" }) <br />@html.validationmessagefor(model => model.password, "", new { @class = "text-danger" }) <div class="col-md-10"> @html.editorfor(model => model.password, new { htmlattributes = new { @class = "form-control input" } }) </div> </div> <div class="form-group"> @html.label("confirm password", htmlattributes: new { @class = "control-label col-md-2 bold" }) <br />@html.validationmessagefor(model => model.confirmpassword, "", new { @class = "text-danger" }) <div class="col-md-10"> @html.editorfor(model => model.confirmpassword, new { htmlattributes = new { @class = "form-control input" } }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="register" class="opc_button" /> </div> </div> </div> } </div> </div> </div> if there validation errors on of fields error message displayed below label expected , wanted. on controller have custom logic errors , adding them modelstate follows:
else { //this email address assigned user modelstate.addmodelerror("email address : ", "error! must enter email address unique account."); return view(model); } if uncomment validationsummary on page display custom server side error display single validation errors want underneath labels. there way can set validation summary ignore values being listed individually , return server side validation errors?
the first string parameter of modelstate.addmodelerror method key later used bind message model property.
if want display error message next email label, make first parameter of addmodelerror match property name:
modelstate.addmodelerror("email", "error! email used...");
Comments
Post a Comment