지금 내가하고있는 일은 TempData를 사용하여 내 ViewModel을 다른 Action으로 전달하는 것입니다.TempData를 사용하지 않고 ActionResults간에 ViewModel 전달
그러나 제 동료는 LoadBalancers 전에 TempData에 경험이있어서 TempData를 사용해서는 안된다는 사실을 알려 왔습니다.
여기 내 컨트롤러의 일부로 내가하고 싶은 것을 볼 수 있습니다. TempData 또는 Session을 사용하지 않고 어떻게 동일한 프로세스를 수행 할 수 있습니까? 감사합니다.
--EDIT--
public ActionResult Create()
{
MyViewModel viewModel;
if (TempData["viewModel"] != null)
{
viewModel = (MyViewModel)TempData["viewModel"];
//code for getting dropdownlist to show to view
return View(viewModel);
}
viewModel = new RequestViewModel();
//code for getting dropdownlist to show to view
return View(viewModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(MyViewModel viewModel)
{
if (ModelState.IsValid)
{
//collect data, but not yet save to database
TempData["viewModel"] = viewModel;
return RedirectToAction("Confirm");
}
//code to get errors, and dropdownlist items to re-show to view
return View(viewModel);
}
public ActionResult Confirm()
{
if (TempData["viewModel"] != null)
{
var viewModel = (MyViewModel)TempData["viewModel"];
return View(viewModel);
}
return RedirectToAction("Create");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Confirm(MyViewModel viewModel)
{
if (ModelState.IsValid)
{
//save data to database if confirmed
return View(viewModel);
}
return RedirectToAction("Create");
}
는 또한 매개 변수를 통해 redirectToAction하는 뷰 모델을 전달하는 시도했지만 내 뷰 모델은 리디렉션 후 다시 채워야하지 않았다. 코드 :
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(MyViewModel viewModel)
{
if (ModelState.IsValid)
{
//collect data, but not yet save to database
return RedirectToAction("Confirm", viewModel);
}
//code to get errors, and dropdownlist items to re-show to view
return View(viewModel);
}
public ActionResult Confirm(MyViewModel viewModel)
{
if (viewModel != null)
{
//some code
return View(viewModel);
}
return RedirectToAction("Create");
}
[HttpPost]
[ActionName("Review")]
[ValidateAntiForgeryToken]
public ActionResult ConfirmPost(MyViewModel viewModel)
{
if (ModelState.IsValid)
{
//save data to database if confirmed
return View(viewModel);
}
return RedirectToAction("Create");
}
아니가,보기를 확인이다. 사용자가 취소 버튼을 눌러 취소하거나 계속 진행합니다. – jomsk1e
오해 때문에 죄송합니다. 새보기를 확인 하시겠습니까? –
예, 확인은 사용자가 입력 내용의 유효성을 검사 한 다음 계속할 것인지 결정할 수있는 새로운보기입니다. – jomsk1e