调用Action Method,关闭对话框并刷新父项
Call Action Method, close dialog and refresh parent
由于我是MVC5的新手,我可能对此有错误的想法。
我有一个CustomerInfo.cshtml视图,上面列出了CustomerContact。它们旁边是一个"+"图标,它将打开一个对话框窗口,允许他们添加新的CustomerContact。
在打开对话框时,我调用CustomerContactController创建GET方法(将customerId传递给它,将其设置为我的模型,并将其传递给视图)。
保存时,我调用CustomerContactController Create POST方法设置值并保存到数据库。
此时,我如何关闭对话框窗口并刷新父CustomerInfo.cshtml页面,以便新联系人出现在列表中。所有的Action方法都要求我返回一些东西。
我从CustomerInfo.cshtml视图打开对话框,如下所示:
@(Html.Kendo().Window()
.Name("windowContact")
.Title("New Customer Contact")
.LoadContentFrom("Create", "CustomerContact", new { customerId = Model.Id })
.Draggable()
.Width(680)
.Visible(false)
.Events(events => events.Open("centerWindow"))
)
在对话框窗口中,我有一个剃刀形式。这是对话框的底部:
<input type="submit" value="Save" id="btnSave" class="btn btn-primary" />
<input type="button" value="Cancel" id="btnCancel" class="btn btn-default" />
}
<script>
$("#btnCancel").click(function () {
$("#windowContact").data("kendoWindow").close();
});
</script>
以下是我目前正在做的操作,它将带我返回CustomerInfo视图,但会进行刷新。使用AJAX来顺利完成这项工作的唯一方法是什么?
return RedirectToAction("CustomerInfo", "Customer", new { id = custContact.CustomerId });
通过jQuery Ajax发布Create view的表单数据。类似:
$.ajax({
url: '/Create/CustomerContact',
type: 'post',
contentType: "application/x-www-form-urlencoded",
data: $form.serialize(),
success: function (data, status) {
// here close the window and refresh parent
// if your new window is opened in iframe
window.parent.location.reload();
$("#windowContact").data("kendoWindow").close();
// if your new window is opened by window.open() method.
window.opener.location.reload();
self.close();
},
error: function (xhr, desc, err) {
alert("Desc: " + desc + "'nErr:" + err);
}
});
希望它对你有用,谢谢。
相关文章:
- 着色引导框对话框
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- OnsenUI、Angular和在警报对话框后刷新UI组件
- 关闭模式对话框而不刷新父级
- 刷新jquery中弹出的ui对话框
- 调用Action Method,关闭对话框并刷新父项
- 如何停止'确认表单重新提交'对话框,同时刷新页面
- 从 CRM 4 中的模式对话框刷新父窗体 - 并不总是有效
- 无法设置 jquery 对话框.InnerHtml(某些内容)无需刷新页面
- jQuery 模式对话框在刷新后的第一页上工作正常,但在此之后的任何其他页面上都无法正常工作,除非刷新
- 对话框模式关闭时刷新Iframe
- 正在刷新jQuery对话框数据
- 在关闭jQuery对话框之前刷新页面
- 当用户尝试刷新/关闭/导航到另一个网页时,显示确认对话框
- 如何在dojo中刷新对话框
- 防止打印对话框刷新页面
- 刷新一个对话框
- Dynamics CRM 2016在线-使用对话框后刷新记录
- 黄瓜,确认页面开始刷新时显示的浏览器对话框
- 我如何使对话框聊天日志滚动到底部不断刷新而不改变鼠标焦点