0

我想显示一个确认对话框,如果用户按“继续”,表单将被提交。

这是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>

但是确认后,表格没有提交。这里有什么问题?有任何想法吗??

4

1 回答 1

1

尝试改变这个:

var form = $('transferForm', this);
$(form).submit();

到:

$("#IDofForm").submit();

因为this在对话框事件处理程序内部可能没有引用您认为它所做的事情,并且您可能没有带有transferForm标记名的元素(这是您在不使用#.在选择器前面时的目标)?

于 2012-08-24T12:52:10.147 回答