나는 다음과 같은 특성을 가진 방문을라는 개체가 모델 바인더에 객체를 전달하고 경우 업데이트되는 일부 값을 방지 할 수 있습니다 PatientID StatusID 편집에서 어떻게 내가
사용자는 다음과 같은 두 가지 속성을 편집 할 수 있습니다 볼 타임 스탬프 : - 주 DoctorID 그래서 나는 다음과 같이 내 편집보기에 숨겨진 필드와 다른 속성을 추가 한 - 난 내 게시물을 편집 액션 메소드 ,,에 방문 객체를 전달하고 있기 때문에@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Visit</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Note)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Note)
@Html.ValidationMessageFor(model => model.Note)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DoctorID)
</div>
<div class="editor-field">
@Html.DropDownList("DoctorID", String.Empty)
@Html.ValidationMessageFor(model => model.DoctorID)
</div>
<p>
@Html.HiddenFor(model => model.VisitTypeID)
@Html.HiddenFor(model => model.CreatedBy)
@Html.HiddenFor(model => model.Date)
@Html.HiddenFor(model => model.VisitID)
@Html.HiddenFor(model => model.PatientID)
@Html.HiddenFor(model => model.StatusID)
@Html.HiddenFor(model => model.timestamp)
<input type="submit" value="Create" />
내가 내 편집보기의 모든 속성을 포함 haveto하는 다음과 같습니다 : -
[HttpPost]
public ActionResult Edit(Visit visit)
{
if (!(visit.Editable(User.Identity.Name)))
{
return View("NotFound");
}
try
{
if (ModelState.IsValid)
{
repository.UpdateVisit(visit);
repository.Save();
return RedirectToAction("Index");
}
}
catch (DbUpdateConcurrencyException ex)
{
var entry = ex.Entries.Single();
var clientValues = (Visit)entry.Entity;
ModelState.AddModelError(string.Empty, "The record you attempted to edit "
+ "was modified by another user after you got the original value. The "
//code goes here
그래서 내가 이러한 이유로 위의 접근 방식에 대한 걱정 - 1. 공격자가 hiddenfields 값을 수정할 수 있습니다. 2. 내 Visit 모델 클래스에서 [Bind (Include = "....")]를 정의 할 수 없습니다.
그래서 나는이 방법을 계속 사용할지 여부를 결정 드릴 수 없습니다 또는
ViewModel을 사용해야합니다. – SLaks
하지만 ViewModle을 사용하면 ViewModel에서 데이터베이스의 타임 스탬프 값이 관련이 없으므로 타임 스탬프 값을 추적 할 수 있습니다 .. 내 작업 메서드 에서처럼 DbUpdateConcurrencyException을 확인하면 아니요 타임 스탬프 값은 편집 과정에서 발견되었습니다 ... –
답장을 보내 주시면 ViewModel – SLaks