JQuery 模态弹出问题中的 ASP.net MVC 3 不引人注目的客户端验证
当我尝试在应用程序中实现 ASP.net MVC 3 Unobtrusive Client Validations 时,呈现的 html 没有生成由 JQuery 生成的 span 标签。
我只得到了以下渲染 html,并且我使用 JQuery 模式弹出窗口作为我的部分视图的容器。
<input data-val="true" data-val-required="The City field is required." id="City" name="City" type="text" value="Seattle" />
但是,当我在没有 JQuery Modal 弹出窗口的情况下使用不引人注目的客户端验证时,它在同一应用程序中可以正常工作,如下所示。
<div class="editor-field">
<input data-val="true" data-val-required="The City field is required." id="City" name="City" type="text" value="Seattle" />
<span class="field-validation-valid" data-valmsg-for="City" data-valmsg-replace="true"></span>
</div>
当我在 JQuery Modal Popup 中使用 Unobtrusive Client 验证时,有什么需要实现的吗?
JQuery 弹出代码
$(document).ready(function () {
$('#actionPanelDialogs div').dialog({
autoOpen: false,
modal: true,
width: 700,
appendToBody: true
});
$('#actions a').click(function (event) {
event.stopPropagation();
event.preventDefault();
var link = $(this);
var action = link.attr('href');
var dialogDivId = link.attr('rel');
var dialogDiv = $('#' + dialogDivId);
$.get(action, null, function (data) {
dialogDiv.html(data);
dialogDiv.dialog('open');
});
return false;
});
});
When I tried to implement ASP.net MVC 3 Unobtrusive Client Validations in the application, the rendered html didn't generate the span tags which are generated by JQuery.
I have only got following rendering html and I used JQuery modal popup as a container for my partial View.
<input data-val="true" data-val-required="The City field is required." id="City" name="City" type="text" value="Seattle" />
However, when I used Unobtrusive Client validation with out JQuery Modal pop up it works correctly as follows in same application.
<div class="editor-field">
<input data-val="true" data-val-required="The City field is required." id="City" name="City" type="text" value="Seattle" />
<span class="field-validation-valid" data-valmsg-for="City" data-valmsg-replace="true"></span>
</div>
Is there any thing that I need to implement when I use Unobtrusive Client validations in JQuery Modal Popup?
JQuery Popup Code
$(document).ready(function () {
$('#actionPanelDialogs div').dialog({
autoOpen: false,
modal: true,
width: 700,
appendToBody: true
});
$('#actions a').click(function (event) {
event.stopPropagation();
event.preventDefault();
var link = $(this);
var action = link.attr('href');
var dialogDivId = link.attr('rel');
var dialogDiv = $('#' + dialogDivId);
$.get(action, null, function (data) {
dialogDiv.html(data);
dialogDiv.dialog('open');
});
return false;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须手动触发对添加到 DOM 的任何新元素的解析。
如果您使用的是 jQuery UI
You have to manually trigger a parse of any new elements added to the DOM.
If you are using jQuery UI
发现问题,
我使用表单 html 创建表单元素,如下所示。
当我使用 Html 助手时,它工作正常。
Found the problem,
I've used form html to create form element as follows.
When I used Html helper it worked correctly.
对于任何使用引导模式的人,请使用以下代码:
感谢 Josh 的勇气。
For anyone using bootstrap modals use the following code:
Thanks to Josh for the guts of it.
尝试了所有方法,这对我有用:
Tried all approaches and this is what worked for me: