[英]Call Action Method, close dialog and refresh parent
由於我是MVC5的新手,所以我可能會錯誤地考慮這一點。
我有一個CustomerInfo.cshtml視圖,其中列出了CustomerContacts。 在他們旁邊是“ +”圖標,它將打開一個對話框窗口,並允許他們添加新的CustomerContact。
在對話框打開時,我調用CustomerContactController創建GET方法(將它傳遞給customerId將其設置為我的模型並將其傳遞給視圖)。
保存時,我調用CustomerContactController創建POST方法,設置值並保存到db。
此時,如何關閉對話框窗口並刷新父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視圖的表單數據。 喜歡:
$.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);
}
});
希望它對您有用,謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.