1

我有一个 mvc4 Web 应用程序一个带有表单的页面

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

<fieldset>
    <legend>News</legend>
    <div class="editor-label">
        @Html.LabelFor(model => model.title)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.title)
        @Html.ValidationMessageFor(model => model.title)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.summery)
    </div>
    <div class="editor-field">
        @Html.TextAreaFor(model => model.summery)
        @Html.ValidationMessageFor(model => model.summery)
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}

我想在表单有效后调用一个显示确认对话框的函数(jquery)

$("#dialog-message").dialog({
        modal: true,
        resizable: false,
        draggable: false,
        title: title, closeOnEscape: false,
        buttons: {
            "OK submit": function () {

            },
            "Cancel Submit": function () {

            }
        }
    });

这样做最好的方法是什么?我希望验证表单,如果有效则下一步显示确认消息,如果按下“确定提交”以提交表单,则下一步。

4

1 回答 1

1

尝试这个:

$(formSelector).submit(function(){
   var frm = $(this);
  if (frm.validate()) {
  $("#dialog-message").dialog({
        buttons: {
        "OK submit": function () {
              //not sure - here can be a mistake
              frm.unbind('submit');
             frm.sumbit();

        },
        "Cancel Submit": function () {

        }
    }
 });
 }
 return false;

});

如果你不想显示自定义对话框,你可以使用这个:

 $(formSelector).submit(function(){
  var frm = $(this);
  if (frm.validate()) {
          return confirm("Want to submit?");
     }
  return false;
 });
于 2013-03-20T17:25:46.080 回答