单击删除链接时,我想在我的学生控制器中调用 DeleteConfirmed 方法。
学生控制器代码
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Student student = db.Students.Find(id);
db.Students.Remove(student);
db.SaveChanges();
return RedirectToAction("Index");
}
Index.cshtml 在单击时具有删除链接(最后一行代码),我希望调用 DeleteConfirmed 但下面希望 delete.cshtml 存在。我不想显示删除视图,只希望删除发生异步的。
@model IEnumerable<SMS.Model.Student>
@{
ViewBag.Title = "Student";
}
<h2>Student</h2>
@using (Html.BeginForm()) {
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.RegistrationNo)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.MiddleName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.DateofBirth)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RegistrationNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.MiddleName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateofBirth)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Ajax.ActionLink("Delete", "Delete", new { id = item.Id },new AjaxOptions { HttpMethod = "Post"})
</td>
</tr>
}
}