添加验证与MVC 3及jQuery的验证程序执行时间 [英] Adding validation with MVC 3 & jQuery Validator in execution time
本文介绍了添加验证与MVC 3及jQuery的验证程序执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有被加载页面时通过C#提供的验证形式,
像这样呈现的字段:
I have a form with validation rendered by c# when the page is loaded, the rendered fields like so:
<input autocomplete="off" class="input-validation-error" data-val="true" data-val-number="The field Idade must be a number." data-val-range="message here" data-val-range-max="25" data-val-range-min="16" data-val-required="The Idade field is required." id="Content_MyFieldId" maxlength="3" name="Content.MyFieldId" value="0" type="text">
和我试图把一个新的HTML对象等于与jQuery的例子,但是当我提交表单这一新的领域未验证。
and I'm trying put a new html object equals the example with jQuery, but this new field is not validated when I submit the form.
有办法使用jQuery此字段中添加验证?
Have a way to add validation in this field using jQuery?
PS:我不想用手动的方法,像这样:
$("#field").rules("add", {
required: true,
messages: {
required: "Required input"
}
});
由于我在输入字段的规则,我只是想使用它。
Because I have the rules in the input field, I only want to apply it.
推荐答案
感觉就像一个黑客攻击的一位,但在这里是如何我已经做到了。
Feels like a bit of a hack, but here's how I've done it.
// Target Form
var $form = $("**form selector**");
// Unbind existing validation
$form.unbind();
$form.data("validator", null);
// Check document for changes
$.validator.unobtrusive.parse(document);
// Re add validation with changes
$form.validate($form.data("unobtrusiveValidation").options);
富
这篇关于添加验证与MVC 3及jQuery的验证程序执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文