Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. ValidateModel(viewModel);
  2.  
  3. TryValidateModel(viewModel)
  4.  
  5. [HttpGet]
  6. public ActionResult Index()
  7. {
  8. var viewModel = new RandomVieModel();
  9.  
  10. ValidateModel(viewModel); //For example
  11.  
  12. return View(viewModel);
  13. }
  14.  
  15. [HttpPost]
  16. public ActionResult Index(RandomViewModel viewModel)
  17. {
  18. if(!ModelState.IsValid)
  19. {
  20. return View(viewModel);
  21. }
  22.  
  23. return RedirectToAction("SomethingNew);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement