C# MVC 5-jQueryUI对话框视图未显示
我在一个MVC网站上工作,对于我的删除功能,我决定使用jQueryUI对话框来显示一个弹出式对话框,供用户确认是否要删除该对象。我的问题是它没有按预期显示,当我选择删除时,我可以看到我的部分视图对话框弹出一秒钟,然后我被重定向到另一个页面,该页面显示我的确认消息和要删除的按钮 这是我的删除控制器:C# MVC 5-jQueryUI对话框视图未显示,c#,asp.net-mvc,model-view-controller,asp.net-mvc-5,jquery-ui-dialog,C#,Asp.net Mvc,Model View Controller,Asp.net Mvc 5,Jquery Ui Dialog,我在一个MVC网站上工作,对于我的删除功能,我决定使用jQueryUI对话框来显示一个弹出式对话框,供用户确认是否要删除该对象。我的问题是它没有按预期显示,当我选择删除时,我可以看到我的部分视图对话框弹出一秒钟,然后我被重定向到另一个页面,该页面显示我的确认消息和要删除的按钮 这是我的删除控制器: //Deletes a selected club [HttpGet] public ActionResult DeletePartialView(int? id) //Origina
//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>
)
这是它当前的显示方式:
这就是我的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>
}
@model-ultimateorganiser.Models.Club
@{
ViewBag.Title=“删除”;
}
您确定要删除此俱乐部吗?
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
@ActionLink(“返回列表”、“索引”)
}
您可以在jQuery
绑定中使用preventDefault
$("#deleteClub-opener").click(function (e) {
e.preventDefault();
$("#DelteClub-dialog").dialog("open");
});
或者,也可以在绑定函数中
返回false
,以防止事件传播 到目前为止,你的表现还不错。要进行删除工作,请在“开始”窗体后的“删除部分”视图中添加以下内容
<input type="hidden" name="id" value="@Model.Id"/>
请检查此代码,并告诉我使用此对话框的另一个问题。
只使用此库
打开对话框
$(文档).ready(函数(){
$(函数(){
$.noConflict(真);
$(“#对话框”)。对话框({
自动打开:错误,
真的,
可调整大小:正确,
dialogClass:“警报”,
莫代尔:对
});
$(“#btnCreate”)。单击(函数(){
$('dialog')。dialog('open');
});
});
});
名称
名称
年龄
您需要取消默认重定向。添加返回false代码>在$(#DelteClub对话框)之后。对话框(“打开”)代码>这似乎不起作用,由于某种原因,当我添加该行时,我再也看不到弹出的flash,而它似乎直接跳入允许显示对话框的页面是的,但现在删除操作不再出现works@CathalODonnell,您的对话框需要一个按钮将值发布到您的控制器方法。因为您没有显示相关的代码(对话框中有什么?),所以有点不清楚您实际想要做什么。我已经更新了我的问题,以包含我的部分观点
<input type="hidden" name="id" value="@Model.Id"/>
please check this code.and tell me another problem for using the dialog box.
only use this library
<html>
<head>
<link href="~/library/jquery-ui.min.css" rel="stylesheet" />
<script src="~/library/jquery.js"></script>
<script src="~/library/jquery-ui.min.js"></script>
</head>
<div>
<button id="btnCreate" class="btn-btn-primary">open the dialog</button>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$.noConflict(true);
$("#dialog").dialog({
autoOpen: false,
draggable: true,
resizable: true,
dialogClass: "alert",
modal: true
});
$("#btnCreate").click(function () {
$('#dialog').dialog('open');
});
});
});
<body>
<div id="dialog" style ="display:none" class="form" title="Basic dialog">
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<th>Name</th>
<td><input type ="text" id="txtName" style= "width:200px" />
</tr>
<tr>
<th>Age</th>
<td><input type ="text" id="txtAge" style= "width:200px" />
</tr>
<tr>
<td><input type="submit" value="Create" id="btnCreateId" class="btn btn-Sucess" />
<td><input type="button" value="Cancel" id="txtCancel" class="btn btn-danger"/>
</tr>
</table>
</div>
</body>
<html>