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