更新时间:2023-01-07 08:27:52
如果你不绝对需要向导页上AJAX,可以通过一个成功的表单POST之后返回不同的视图来做到这一点。
If you don't absolutely need AJAX on the wizard page, it is possible to do this by returning different views after a successful form POST.
在控制器:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult DoSomethingLong(int somethingId, int step)
{
MyModelType myModel = MyModelFactory.Fetch(somethingId);
switch(step)
{
case 1:
return View("Step1", myModel);
break;
case 2:
return View("Step2", myModel);
break;
}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DoSomethingLong(int somethingId, int step)
{
MyModelType myModel = MyModelFactory.Fetch(somethingId);
if (TryUpdateModel(myModel))
{
//Successful update. Send to next step.
return RedirectToAction("DoSomethingLong", new {somethingId = somethingId, step = step + 1}
}
else
{
//Update failed, redisplay current View with validation errors.
return View(myModel);
}
}