我有以下 Post Edit 操作方法,其中包括一个 [Bind] 列表以限制模型绑定器将绑定的属性:-
[HttpPost]
public ActionResult Edit(Bind(Include="Note,DoctorID,VisitID,StatusID")] Visit visit)
{
if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name)))
{ try
{if (ModelState.IsValid)
{ entities.Entry(visit).State = EntityState.Modified;
repository.Save();
return RedirectToAction("Index"); } }
catch (DbUpdateConcurrencyException ex)
{ var entry = ex.Entries.Single();
var clientValues = (Visit)entry.Entity;
//code goes here
但是由于访问对象包含绑定列表中未包含的其他属性,所以我如何从数据库中检索访问对象属性的当前值。提示:- 我正在使用实体框架和数据库优先方法。BR
更新:- 这是 GET EDIT 操作方法:-
public ActionResult Edit(int id)
{
Visit visit = repository.GetVisit(id);
if ((visit.EditableByAssingedDoctor(User.Identity.Name)) || (visit.EditableByCreatedBy(User.Identity.Name)))
{
ViewBag.DoctorID = new SelectList(Membership.GetAllUsers(), "Username", "Username", visit.DoctorID);
ViewBag.StatusID = new SelectList(repository.FindAllVisitStatus(), "StatusID", "Description", visit.StatusID);
return View(visit);
}
else { return View("NotFound");}
}