WebGrid可以编辑吗?
答案 0 :(得分:2)
制作新的View Edit.cshtml并使用Hiddenfield获取将传递给makel以获取更新数据的ID。
public ActionResult Edit(WebdridDBModel model, string id)
{
var editItem = from e in dc.EDetails where e.Id ==Convert.ToInt32(id) select e;
var editList = editItem.ToList();
model.FirstName= editList[0].FirstName;
model.LastName=editList[0].LastName;
model.Salary =Convert.ToInt32( editList[0].Salary);
return View(model);
}
public ActionResult EditSubmit(WebdridDBModel model, string id)
{
EDetail ed = dc.EDetails.Single(P=>P.Id==model.Id);
ed.FirstName = model.FirstName.Trim();
ed.LastName = model.LastName.Trim();
ed.Salary = model.Salary.ToString();
dc.SubmitChanges();
return RedirectToAction("Index");
}