유효성 검사 오류 bu의 경우 동일한 양식을 다시 렌더링하면 올바른 디자인 패턴이 리디렉션되지 않습니다. 작업이 성공한 경우에만 리디렉션해야합니다.
예 :
[HttpPost]
public ActionResult Index(MyViewModel model)
{
if (!ModelState.IsValid)
{
// some validation error occurred => redisplay the same form so that the user
// can fix his errors
return View(model);
}
// at this stage we know that the model is valid => let's attempt to process it
string errorMessage;
if (!DoSomethingWithTheModel(out errorMessage))
{
// some business transaction failed => redisplay the same view informing
// the user that something went wrong with the processing of his request
ModelState.AddModelError("", errorMessage);
return View(model);
}
// Success => redirect
return RedirectToAction("Success");
}
이 패턴은 일부 오류가 발생하는 경우에 대비하여 모든 모델의 값을 보존 할 수 있으며 동일한보기를 다시 표시해야합니다.
감사합니다. 이 주제가 유사한 문제를 발견했습니다. http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data –