Asp.net mvc 3 MVC3,表单验证,其中html通过ajax调用推出
我正在对页面上的表单进行验证 我有一个动作是通过ajax引入html,在这种情况下,部分视图被推出。在此表单上,我的验证无效 HTML被推出,我也用它推出js进行了测试,但仍然没有成功:Asp.net mvc 3 MVC3,表单验证,其中html通过ajax调用推出,asp.net-mvc-3,validation,Asp.net Mvc 3,Validation,我正在对页面上的表单进行验证 我有一个动作是通过ajax引入html,在这种情况下,部分视图被推出。在此表单上,我的验证无效 HTML被推出,我也用它推出js进行了测试,但仍然没有成功: <!-- form, AJAX and validation --> <script type="text/javascript" src="/NetSite/Scripts/Tools/jqueryplugins/jquery.form.js"></script> <
<!-- form, AJAX and validation -->
<script type="text/javascript" src="/NetSite/Scripts/Tools/jqueryplugins/jquery.form.js"></script>
<script type="text/javascript" src="/NetSite/Scripts/jqueryMain/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript" src="/NetSite/Scripts/jqueryMain/jquery.validate.1.9.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="/NetSite/Scripts/jqueryMain/jquery.validate.unobtrusive.min.js"></script>
<form action="/Transfer/ExtendExpirationDate" id="ExtendExpirationDateForm" method="post">
<input data-val="true" data-val-required="The XPhase field is required." id="Detail_XPhase" name="Detail.XPhase" type="hidden" value="870033f4-670e-4315-a23a-fc6ebb24cafe" />
<input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Detail_Id" name="Detail.Id" type="hidden" value="100138062" />
<input data-val="true" data-val-number="The field Id must be a number." data-val-required="Response required!" id="DaysToExpire_Id" name="DaysToExpire.Id" type="hidden" value="100138062" />
<table class="siteTable">
<tbody>
<tr>
<th style="width: 40%;">Posted Date</th>
<td style="width: 60%;">08/27/2012</td>
</tr>
<tr>
<th>Expiration Date</th>
<td>09/03/2012</td>
</tr>
<tr>
<th>Current Days to Expiry</th>
<td>7</td>
</tr>
<tr>
<th>New Days to Expiry</th>
<td>
<input data-val="true" data-val-digits="The field should contain only digits" data-val-number="The field DaysToExpire must be a number." data-val-range="Value should be greater than 0" data-val-range-min="1" data-val-required="Response required!" id="DaysToExpire_DaysToExpire" maxlength="3" name="DaysToExpire.DaysToExpire" size="4" type="text" value="14" />
<span class="field-validation-valid" data-valmsg-for="DaysToExpire.DaysToExpire" data-valmsg-replace="true"></span>
</td>
</tr>
<tr>
<th class="empty"></th>
<td><button type="submit" title="Update" id="ExtendExpirationUpdateButton" class="gradientbutton gradientsmall gradientorange">Update</button></td>
</tr>
</tbody>
</table>
</form>
不引人注目的验证器仅连接到原始dom加载事件上,而不连接到Subquest插件上 将表单插入DOM时,调用
$.validator.unobtrusive.parse("form");
连接表单以进行验证
问候
Si由于此表单是由cluetip拉入的,因此我已将其添加到OnShow nethod中
<script type="text/javascript">
$('.ExtendExpirationDate').cluetip({
attribute: 'rel',
showTitle: true,
sticky: true,
closeText: JSGlobalVars.CloseImagePath,
ajaxCache: false,
arrows: true,
dropShadow: false,
activation: 'click', //click, hover
height: 'auto',
closePosition: 'title',
width: '400px',
onShow: function (ct, ci) {
$.validator.unobtrusive.parse("ExtendExpirationDateForm"); //client side validation
}
});
</script>
$('.ExtendExpirationDate').cluetip({
属性:“rel”,
节目名称:真的,
斯蒂奇:是的,
closeText:JSGlobalVars.CloseImagePath,
ajaxCache:false,
箭头:是的,
dropShadow:false,
激活:'单击',//单击,悬停
高度:“自动”,
关闭位置:'标题',
宽度:“400px”,
onShow:功能(ct、ci){
$.validator.unobtrusive.parse(“ExtendExpirationDateForm”);//客户端验证
}
});
当上述方法无效时,我将其添加到我的控制中。还是不走运
<script type="text/javascript">
$(document).ready(function() {
$.validator.unobtrusive.parse("ExtendExpirationDateForm"); //client side validation
});
</script>
$(文档).ready(函数(){
$.validator.unobtrusive.parse(“ExtendExpirationDateForm”);//客户端验证
});
我使用firebug 1.10.2复制了以上两个版本。它不起作用。我已经完成了以下2项(在我下面的回答中)嗨,它将无法在该选择器上找到表单,或者在id前面加上一个#,或者在我的回答中使用“表单”,谢谢你的帮助。我正在使用cluetip onshow并改为“form”
<script type="text/javascript">
$('.ExtendExpirationDate').cluetip({
attribute: 'rel',
showTitle: true,
sticky: true,
closeText: JSGlobalVars.CloseImagePath,
ajaxCache: false,
arrows: true,
dropShadow: false,
activation: 'click', //click, hover
height: 'auto',
closePosition: 'title',
width: '400px',
onShow: function (ct, ci) {
$.validator.unobtrusive.parse("ExtendExpirationDateForm"); //client side validation
}
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$.validator.unobtrusive.parse("ExtendExpirationDateForm"); //client side validation
});
</script>