asp.net mvc - It is possible to combine ValidationSummary(true) and ModelState.AddError("field", "error")? -
i use validationsummary(true) print model validation errors in
1 place , property validation errors near each field.-
in controller add property error : modelstate.adderror("property","error")
i see message validation error property got validation-summary-errors div although have no model error. doing wrong , why div generated if have no model errors?
<div class="validation-summary-errors"> <ul> <li style="display:none"></li> </ul> </div>
you have add twice so:
string errormessage = "the error message"; //will show in summary modelstate.addmodelerror(string.empty, errormessage); //will show prop modelstate.addmodelerror("prop", errormessage);
or can change call so:
@html.validationsummary(false)
changing argument false
include property errors. param name in validationsummary
excludepropertyerrors
, passing true
excluding them.
Comments
Post a Comment