asp.net - Range validation error is always showing -
this razor:
<div class="row form-group"> <label class="control-label col-md-2">number answer</label> <div class="col-md-6"> @html.textboxfor(t => t.selectedquestions, new { style = "width: 10%", @class = "form-control" }) @html.validationmessagefor(t => t.selectedquestions) </div> </div>
this html generated:
<div class="row form-group"> <label class="control-label col-md-2">number answer</label> <div class="col-md-6"> <input class="input-validation-error form-control" data-val="true" data-val-number="the field selectedquestions must number." data-val-range="the value entered must bigger zero." data-val-range-max="6" data-val-range-min="1" data-val-required="the selectedquestions field required." id="selectedquestions" name="selectedquestions" style="width: 10%" type="text" value="3"> <span class="field-validation-error" data-valmsg-for="selectedquestions" data-valmsg-replace="true">the value entered must bigger zero.</span> </div> </div>
and that's how have defined property:
cs code
[range(1, 6, errormessage = "the value entered must bigger zero.")] [required] public int selectedquestions { get; set; }
that field have valid data in when page loads, still showing red validation error under field, why?
also if delete number in , type else, still red , doesn't go away.
if there stuff should add css
maybe? please let me know.
your bundleconfig.cs file should have following javascript files registered :
bundles.add(new scriptbundle("~/bundles/jqueryval").include( "~/scripts/jquery.validate*"));
and following css needs in css (which guess if you're seeing red) :
.field-validation-error { font-weight:bold; color:red; } .validation-summary-errors { font-weight:bold; color:red; }
make sure _layout.cshtml has thew following @ bottom :
@scripts.render("~/bundles/jquery") @scripts.render("~/bundles/jqueryval") @scripts.render("~/bundles/bootstrap")
and long have following either in _layout or on page should work :
@{html.enableclientvalidation(); }
Comments
Post a Comment