Guest User

Untitled

a guest
Aug 22nd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. asp.net mvc keep object alive, information
  2. [HttpPost]
  3. public ActionResult Index(LoginModel loginModel)
  4. {
  5. if (ModelState.IsValid)
  6. {
  7. // some lines of code . bla bla bla
  8. TempData["loginModel"] = loginModel;
  9. return RedirectToAction("index", "premium");
  10. }
  11. ...
  12. }
  13.  
  14. public ActionResult Index()
  15. {
  16. var loginModel = TempData["loginModel"] as LoginModel;
  17. ...
  18. }
  19.  
  20. Object reference not set to an instance of an object.
  21.  
  22. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  23.  
  24. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  25.  
  26. Source Error:
  27.  
  28.  
  29. Line 22:
  30. Line 23: var loginModel = TempData["loginModel"] as LoginModel;
  31. Line 24: string username = loginModel.username;
  32. Line 25: string password = loginModel.password;
  33. Line 26: premiumModel.username = username;
Add Comment
Please, Sign In to add comment