我知道这个问题的标题不是很漂亮。我有更好的表达方式。
让我们看看下面的代码:
查看删除操作:
@model LearningMVC.Models.Blog
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<fieldset>
<legend>Blog</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.URL)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.URL)
</div>
</fieldset>
@using (Html.BeginForm()) {
<p>
<input type="submit" value="Delete" /> |
@Html.ActionLink("Back to List", "Index")
</p>
}
删除操作的控制器操作
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Blog blog = db.Blogs.Find(id);
db.Blogs.Remove(blog);
db.SaveChanges();
return RedirectToAction("Index");
}