1. Controller Action Method:
// GET: PersonalDetails/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PersonalDetail personalDetail = db.PersonalDetails.Find(id);
if (personalDetail == null)
{
return HttpNotFound();
}
return View(personalDetail);
}
// POST: PersonalDetails/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
PersonalDetail personalDetail = db.PersonalDetails.Find(id);
db.PersonalDetails.Remove(personalDetail);
db.SaveChanges();
return RedirectToAction("Index");
}
2. Delete View Record
@model WebApplication1.Models.PersonalDetail
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>PersonalDetail</h4>
<hr />
<dl class="dl-horizontal">
<dt>@Html.DisplayNameFor(model => model.FirstName)
</dt>
<dd>@Html.DisplayFor(model => model.FirstName)
</dd>
<dt>@Html.DisplayNameFor(model => model.LastName)
</dt>
<dd>@Html.DisplayFor(model => model.LastName)
</dd>
<dt>@Html.DisplayNameFor(model => model.Age)
</dt>
<dd>@Html.DisplayFor(model => model.Age)
</dd>
<dt>@Html.DisplayNameFor(model => model.Active)
</dt>
<dd>@Html.DisplayFor(model => model.Active)
</dd>
</dl>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" />
|
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>
Không có nhận xét nào:
Đăng nhận xét