使用 JQuery.Ajax 进行 MVC 验证
我正在尝试验证 JQuery 模型对话框中的一个表单,该对话框动态加载从 jquery ajax 调用生成的视图,
页面上已经有一个表单,并且该表单正在另一个表单下创建,一切似乎都正常,但是我不确定是否可以在第二个表单上使用常规 MVC 验证,因为它是动态创建的。
这是主
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("UpdateFund", "AdministerFundFeature", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
<fieldset>
...
<input type="submit" value="Submit" />
</fieldset>
<%} %>
<div id="GrantRecipDialog" title="Add/Edit Grant Recipiant">
<div id="GrantRecipContent"></div>
</div>
按钮上的 HTML 视图,单击此函数将触发填充新表单的 div
var url = "<%: Url.Action( "AddOrUpdateGrantRecip", "AdministerFundFeature") %>" + "?aGrantId=" + aGrantId + "&aFundId=" + aFundId;
$.ajax({
url: url,
success: function (data) {
$('#GrantRecipContent').html(data); /*place the data here, and rerender the section*/
$('#GrantRecipDialog').dialog("open");
},
error: function () { alert("There was a problem with your request, please resubmit your request."); },//??
complete: function() {}
});
}
,这是在弹出窗口中呈现的视图
<% Html.EnableClientValidation(); %>
<% using (Ajax.BeginForm("updateGrant", "AdministerFundFeature",
new AjaxOptions { OnComplete="function(){onGrantRecipUpdate()}", OnFailure="function(){return onGrantFail()}"},
new { @id = "frmID" }))
{ %>
<fieldset>
...
</fieldset>
<%}%>
是否可以为弹出窗口挂钩 MVC 验证,它在第一种形式中工作正常,但我不确定如何显式告诉 MVC 为新生成的内容创建验证信息
i am trying to validate a form in a JQuery model dialog that is dynamically loading a view generated from a jquery ajax call
there is already one form on the page and this form is being created under the other form, and everything seems to be orking but I am not sure if its possible to use the regular MVC validation on this second form since its being dynamicly created.
here is the HTML view for the main
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("UpdateFund", "AdministerFundFeature", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
<fieldset>
...
<input type="submit" value="Submit" />
</fieldset>
<%} %>
<div id="GrantRecipDialog" title="Add/Edit Grant Recipiant">
<div id="GrantRecipContent"></div>
</div>
on a button click this function is fired populationg the div with the new form
var url = "<%: Url.Action( "AddOrUpdateGrantRecip", "AdministerFundFeature") %>" + "?aGrantId=" + aGrantId + "&aFundId=" + aFundId;
$.ajax({
url: url,
success: function (data) {
$('#GrantRecipContent').html(data); /*place the data here, and rerender the section*/
$('#GrantRecipDialog').dialog("open");
},
error: function () { alert("There was a problem with your request, please resubmit your request."); },//??
complete: function() {}
});
}
and here is the view that gets rendered in the pop up
<% Html.EnableClientValidation(); %>
<% using (Ajax.BeginForm("updateGrant", "AdministerFundFeature",
new AjaxOptions { OnComplete="function(){onGrantRecipUpdate()}", OnFailure="function(){return onGrantFail()}"},
new { @id = "frmID" }))
{ %>
<fieldset>
...
</fieldset>
<%}%>
is it possible to hook the MVC validation up for the pop up, it works fine in the first form, but I am not sure how to explicitly tell MVC to cerate the validation information for the new for generated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建表单后使用它:
Use this after create the form:
不久前我遇到了这个问题,发现我只需将验证错误输入到 JSON 结果中,并使用 Ajax 表单的完整方法来处理它们。
我找不到我链接到的文章,但确实找到了这个;
http://www.hightech.ir/SeeSharp/aspnet-validation -with-ajax-and-json
I came up against this a while ago, and found that I just had to feed my validation errors into a JSON result and deal with them using the complete method of the Ajax form.
I couldn't find the article I linked to, but did find this;
http://www.hightech.ir/SeeSharp/aspnet-validation-with-ajax-and-json