asp.net mvc - How to add validators for @Html.TextBox() without model -
this part of view
@model bhavin.models.employee @using (html.beginform("buynowform", "home")) { <div class="form-group"> <label>billing address</label> @html.textbox("bill_address", null, new { @class = "form-control valid" }) </div> <p> <input type="submit" value="submit" class="btn btn-primary" /> </p> } i want add required validation it. billing_address textbox not part of models.employee. using mvc5 how add validator?
add data-val , data-val-required attribute html.textbox() shown below.
<script src="~/scripts/jquery-1.10.2.min.js"></script> <script src="~/scripts/jquery.validate.min.js"></script> <script src="~/scripts/jquery.validate.unobtrusive.min.js"></script> @using (html.beginform("","")) { @html.validationsummary() @html.textbox("bill_address", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "billing address required" }) <input type="submit" value="click" id="btnsubmit" /> } note
@html.validationsummary()used printing validation message.- do not forget include -
validate,unobtrusivejavascript files.
Comments
Post a Comment