我正在制作一个存储客户的页面。客户可以拥有域、联系人和工作。每个联系人/域/工作都具有编辑/删除功能。
每次您希望编辑/删除它时,我都在使用 MVC 4 ASP.NET c#,它会启动一个模态表单。
除了显示的字段外,联系人和域的删除视图完全相同。域删除功能在部分视图中不会触发任何内容。但是,当它作为常规视图在 url 中导航到时,它会成功。联系人删除在部分视图中工作正常。
@model STClient.Models.Domain
@{
ViewBag.Title = "DeleteDomain";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
@using (Html.BeginForm("DeleteDomain", "Client", FormMethod.Post)) {
<div class="modal-header">
<h2>Are you sure you want to delete?</h2>
</div>
<div class="modal-body">
<fieldset>
<div class="display-label">
<h3>
@Html.HiddenFor(model => model.server.ID)
@Html.HiddenFor(model => model.ID)
@Html.DisplayNameFor(model => model.Name):
@Html.DisplayFor(model => model.Name)
</h3>
</div>
<div class="display-label">
<h5>
@Html.DisplayNameFor(model => model.Registrar):
@Html.DisplayFor(model => model.Registrar)
</h5>
</div>
<div class="display-label">
<h5>
@Html.DisplayNameFor(model => model.PrimaryDNS):
@Html.DisplayFor(model => model.PrimaryDNS)
</h5>
</div>
<div class ="display-label">
<h5>
@Html.DisplayNameFor(model => model.SecondaryDNS):
@Html.DisplayFor(model => model.SecondaryDNS)
</h5>
</div>
</fieldset>
</div>
<div class="modal-footer">
<a class="btn" href="">Cancel</a>
<input class="btn btn-danger" type ="submit" value="Delete" />
</div>
}
这是在删除链接用于域的详细信息页面上。
<div class="modal fade" id="deleteDomain-modal"></div>
<script type="text/javascript">
$(function () {
$(".deleteDomain").click(function () {
$.ajax({
url: "/Client/DeleteDomain",
type: "GET",
data: {id: $(this).attr('id')},
dataType: "html",
success: function(e)
{
$("#deleteDomain-modal").html(e);
}
});
$("#deleteDomain-modal").modal();
});
});
</script>
最后在客户端控制器中
public ActionResult DeleteDomain(int id)
{
Domain domain = db.Domains.Find(id);
if (domain == null)
{
HttpNotFound();
}
return PartialView(domain);
}
[HttpPost, ActionName("DeleteDomain")]
public ActionResult DeleteDomainConfirmed(int id)
{
Domain domain = db.Domains.Find(id);
Server server = db.Servers.Find(id);
db.Domains.Remove(domain);
db.SaveChanges();
db.Servers.Remove(server);
db.SaveChanges();
LogDeleteDomain(domain, server);
return RedirectToAction("Index");
}