code_junkie

How can I maintain ModelState with RedirectToAction?

Nov 12th, 2011
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Delete)]
  2. public ActionResult Delete([ModelBinder(typeof(RdfUriBinder))] RdfUri graphUri)
  3. {
  4. if (!ModelState.IsValid)
  5. return Index(); //this needs to be replaced with something that works :)
  6.  
  7. return RedirectToAction("Index");
  8. }
  9.  
  10. ...
  11. if (!ModelState.IsValid)
  12. TempData["ViewData"] = ViewData;
  13.  
  14. RedirectToAction( "Index" );
  15. }
  16.  
  17. public ActionResult Index()
  18. {
  19. if (TempData["ViewData"] != null)
  20. {
  21. ViewData = (ViewDataDictionary)TempData["ViewData"];
  22. }
  23.  
  24. ...
  25. }
  26.  
  27. return View("Index");
  28.  
  29. return Index();
Add Comment
Please, Sign In to add comment