我有一个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>
}
我希望在form有效后调用一个显示确认对话框(jquery)的函数
$("#dialog-message").dialog({
modal: true,
resizable: false,
draggable: false,
title: title, closeOnEscape: false,
buttons: {
"OK submit": function () {
},
"Cancel Submit": function () {
}
}
});
这样做最好的是什么? 我希望表单有效,下一步如果有效则显示确认消息,下一步如果“确定提交” 迫切要提交表格。
答案 0 :(得分: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;
});