Models 폴더에 클래스를 만들고 MyViewModel이라고 부르면 사용자가 편집해야하는 모든 6 개의 속성을 해당 클래스에 정의해야합니다. 보기에서보기를 작성하면 검토 조치로 다시 게시하도록 정의 된 양식 요소 내에 모든 입력 필드를 표시합니다. 보기의 중요한 부분이 될 것입니다 :
MyController에 클래스에서
@model MyViewModel
@using (Html.BeginForm("Review", "MyController"))
{
//here there's your input field
@Html.TextBoxFor(m => m.prop1)
// and so on
}
, 당신은 검토 방법이 검토보기에
public ActionResult Review(MyModel mm)
{
if (ModelState.IsValid)
{
return View(mm);
} else return RedirectToAction("Create");
}
그리고 마침내를 다음과 같이 정의해야합니다, 당신은거야 이 :
public class ViaggioController : Controller
{
public ActionResult Create()
{
var emptyModel = new MyViewModel();
return RedirectToAction("Edit", new { mm = emptyModel });
}
public ActionResult Edit(MyViewModel mm)
{
return View(mm);
}
public ActionResult Review(MyViewModel mm)
{
if (ModelState.IsValid)
{
return View(mm);
}
else
return RedirectToAction("Create");
}
}
:
이
@model MyViewModel
//show up all the field to be reviewed
@Html.DisplayFor(m=>m.prop1)
//and so on
// now a form to pastback again all the data to the edit page
@using (Html.BeginForm("Edit", "MyController"))
{
//here there's your hidden field
@Html.HiddenFor(m => m.prop1)
// and so on
<input type="submit" value="Re-edit the fields"/>
}
컨트롤러 클래스 MyController에 다음 코드를해야합니다
PartialView는 시나리오를 구현하는 데 충분합니다. –