我正在爲MVC網站和我的刪除功能,我決定使用jQuery UI對話框來顯示彈出式對話框,以確認用戶希望刪除該對象。我的問題是,它不會按預期顯示,當我選擇刪除時,我可以在我重定向到顯示我的確認消息和要刪除的按鈕的另一個頁面之前,看到我的部分視圖對話框彈出一秒鐘。MVC 5 - jQueryUI對話框視圖不顯示
這是我的刪除控制器:
//Deletes a selected club
[HttpGet]
public ActionResult DeletePartialView(int? id) //Original: public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Club club = db.Clubs.Find(id);
if (club == null)
{
return HttpNotFound();
}
return PartialView(club);
}
[HttpPost, ActionName("DeletePartialView")]
public ActionResult DeleteConfirmed(int id) //Original: public ActionResult DeleteConfirmed(int id)
{
Club club = db.Clubs.Find(id);
var MembersToDelete = club.ClubMembers.ToList();
foreach (var item in MembersToDelete)
{
db.ClubMembers.Remove(item);
}
db.Clubs.Remove(club);
db.SaveChanges();
return RedirectToAction("Index");
}
這是刪除按鈕,並在其DIV局部視圖:
@Html.ActionLink("Delete", "Delete", new { id = item.ClubID }, new { @class = "btn btn-danger btn-xs" }) |
@*@Html.ActionLink("Delete Partial", "DeletePartialView", new { id = item.ClubID }, new { @class = "btn btn-danger btn-xs" })*@
@Html.ActionLink(
"Delete Partial",
"DeletePartialView",
new { id = item.ClubID },
new
{
@class = "btn btn-danger btn-xs",
id = "deleteClub-opener" //Button ID
})
@* Delete Club Popup*@
<div id="DelteClub-dialog" title="Delete Club">
@Html.Partial("DeletePartialView", new ultimateorganiser.Models.Club())
</div>
這是jQuery代碼:
//Delete Club Dialog Window with effects
$(function() {
$("#DelteClub-dialog").dialog({
autoOpen: false,
height: 500,
width: 600,
show: {
effect: "clip",
duration: 500
},
hide: {
effect: "highlight",
duration: 1000
}
});
//Open Delete Club Dialog Window
$("#deleteClub-opener").click(function() {
$("#DelteClub-dialog").dialog("open");
});
})
;
這是我DeletePartialView是什麼樣子:
@model ultimateorganiser.Models.Club
@{
ViewBag.Title = "Delete";
}
<h3 class="text-warning">Are you sure you want to delete this club?</h3>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-danger" />
@Html.ActionLink("Back to List", "Index")
</div>
}
您需要取消默認重定向。在$(「#DelteClub-dialog」)。dialog(「open」)後添加'return false;' –