我想显示一个确认对话框,如果用户按“继续”,表单将会提交。
这是jquery代码:
$(document).ready(function () {
$('#submit').click(function () {
$('#confirmation-dialog').dialog('open');
return false; // prevents the default behaviour
});
$('#confirmation-dialog').dialog({
autoOpen: false, width: 400, resizable: false, modal: true, //Dialog options
buttons: {
"Continue": function () {
$(this).dialog('close');
var form = $('transferForm', this);
$(form).submit();
return true;
},
"Cancel": function () {
$(this).dialog("close");
return false;
}
}
});
});
这就是形式:
@using (Ajax.BeginForm("Transfer", "Location", null, new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
//OnBegin = "ajaxValidate",
OnSuccess = "updateSuccess"
}, new { @id = "transferForm" }))
{
<div style="width:600px;">
<div class="editorLabel">
@Html.LabelFor(m => m.FromEmail)
</div>
<div class="editorText">
@Html.TextBoxFor(m => m.FromEmail)
</div>
<div class="clear"></div>
<div class="editorLabel">
@Html.LabelFor(m => m.ToEmail)
</div>
<div class="editorText">
@Html.TextBoxFor(m => m.ToEmail)
</div>
<div class="clear"></div>
<p>
<input type="submit" name="submit" value="Transfer" class="btn" id="submit"/>
</p>
</div>
}
<div id="update-message"></div>
<div id="commonMessage"></div>
<div id="confirmation-dialog">
<p>Are you sure you want to proceed with transfer ?
</p>
</div>
但确认后,表格未提交。 这可能有什么问题?任何想法??
答案 0 :(得分:1)
尝试更改此内容:
var form = $('transferForm', this);
$(form).submit();
为:
$("#IDofForm").submit();
作为this
,对话框中的事件处理程序可能不会引用您的想法,并且您可能没有带transferForm
标记名的元素(这就是您所拥有的)不在选择器前使用#
或.
时进行定位?