表单上的MVC提交打开JQuery对话框,等待用户响应
MVC on form submit open JQuery dialog and wait for user response
我有MVC应用程序;在表单内部,当用户单击"保存"按钮时,它应该将表单提交给控制器并保存更改。如果满足某些条件,它将弹出JQuery UI对话框,执行一些ajax调用,要求用户在对话框中输入,并在用户单击对话框中的新"保存"按钮后提交表单。
我的问题是,在表单"保存"按钮单击,对话框出现,但页面立即发布(我可以看到加载器在浏览器选项卡窗口中工作),用户永远不会与对话框交互,因为它在成功的页面发布后消失。我的HTML:
@using (Html.BeginForm("Edit", "LsaPage", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
//some other fields
<input type="submit" name="actionType" value="Save" id="btnFormSubmit"/>
<div id="inctivePageDialog" title="This is JQuery dialog">
<p> Do you wish to terminate LSA Page on Grids?</p>
<div id="termdatebox">
<h5>Enter Page termination date.</h5>
<input class = "datepicker" id="pageTermDate"/>
<button type="submit" id="finalize" value="Save">Save</button>
</div>
</div>
}
和JQuery:
$('#btnFormSubmit').click(function (e) { //form submit button
if (newPageStatus == "I" && pageStatus == "A") { //conditions
$.ajax({
type: 'GET',
url: '@Url.Action("InactivatePage", "LsaPage")',
data: { pageId: "@Model.PageID" },
dataType: 'json',
cache: false,
async: false,
success: function (data) {
var anyActive = 0;
$.each(data, function (index, item) {
//processing
anyActive += 1;
});
if (anyActive > 0) {
$('#inctivePageDialog').dialog("open"); //open the jquery dialog
}
}
});
}
});
//dialog that shows up when conditions are met
$('#inctivePageDialog').dialog({
autoOpen: false,
modal: true,
width: 500,
height: 500,
buttons: {
Yes: function () {
//if user clicks yes on the dialog, it will ask for the date and show new Save button
$('#termdatebox').show(); //show input textbox
$('.ui-button:contains("Yes")').hide(); //hide original dialog Yes button
},
Cancel: function () {
$(this).dialog("close");
}
}
});
//Save button click event on the dialog
$('#finalize').on('click', function (e) {
var termdate = $('#pageTermDate').val();//get user input
$('#inctivePageDialog').dialog('close');
$.ajax({
type: 'POST',
url: '@Url.Action("InactivatePageRelations", "LsaPage")',
data: { pageId: "@Model.PageID", termDt: termdate },
dataType: 'json',
cache: false,
async: false,
success: function (data) {
debugger
$('form').submit();
}
});
});
你应该把e.p preventdefault()作为$('#btnFormSubmit')的第一行代码。点击(function (e){…})它会阻止表单提交事件的执行,这样你就可以执行ajax调用和逻辑
有关调用的更多信息,请查看
您自己通过Ajax发布表单。按钮类型应该是type="button"
,这将防止表单的post返回。
<button type="button" ...>Save</button>
此外,你不应该同时使用ajax和success:…$('form').submit();;这说不通啊。 相关文章:
- 着色引导框对话框
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- CKeditor:更改对话框中的默认选择选项
- 搜索api在mac上显示对话框
- 使用密码对话框Javascript请求帮助
- CKEditor v4:自制插件中对话框的动态标题
- 删除确认对话框在第一次单击时不起作用
- 使用jquery对话框中的箭头键
- 控制流没有在jquery中的对话框中等待
- 让 JavaScript 函数等待 Jquery 对话框模态的结果
- 如何让 jQuery 对话框在显示之前等待
- 等待所有AJAX调用而不显示对话框
- 等待对话框打开,然后运行
- 使jQuery对话框等待post-back或允许自定义html的JavaScript提示
- jquery实现的请等待对话框- safari特有的问题
- 表单上的MVC提交打开JQuery对话框,等待用户响应
- JavaScript对话框弹出事件等待OK被按下
- 在等待来自对话框的用户反馈时出现流量控制问题
- 等待jquery对话框返回
- 如何使对话框按钮等待来自另一个对话框的响应