Controller Code:
[HttpGet]
public ActionResult Delete(int ? id)
{
tbl_employee em = db.tbl_employee.Where(x => x.emp_id == id).SingleOrDefault();
return View(em);
}
[HttpPost]
public ActionResult Delete(int? id,tbl_employee emp)
{
tbl_employee em = db.tbl_employee.Where(x => x.emp_id == id).SingleOrDefault();
db.tbl_employee.Remove(em);
db.SaveChanges();
return RedirectToAction("Index");
}
View Code:
@model crdu.Models.tbl_employee
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
@using (Html.BeginForm("Delete","Home",FormMethod.Post))
{
@Html.DisplayFor(x=>x.emp_name , new {@class = "form-control" })
@Html.DisplayFor(x => x.emp_email, new { @class = "form-control" })
@Html.DisplayFor(x => x.emp_contact, new { @class = "form-control" })
<input type="submit" value="delete" class="btn btn-danger" />
}
Comments
Post a Comment