Guest User

Untitled

a guest
Jan 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public ActionResult Index()
  2. {
  3. ViewData["foo"] = "bar";
  4. return View();
  5. }
  6.  
  7. <div>@ViewData["foo"]</div>
  8.  
  9. public ActionResult Index()
  10. {
  11. ViewBag.foo = "bar";
  12. return View();
  13. }
  14.  
  15. <div>@ViewBag.foo</div>
  16.  
  17. public class MyViewModel
  18. {
  19. public string Foo { get; set; }
  20. }
  21.  
  22. public ActionResult Index()
  23. {
  24. var model = new MyViewModel { Foo = "bar" };
  25. return View(model);
  26. }
  27.  
  28. @model MyViewModel
  29. <div>@Html.DisplayFor(x => x.Foo)</div>
  30.  
  31. public ActionResult Foo()
  32. {
  33. TempData["foo"] = "bar";
  34. return RedirectToAction("bar");
  35. }
  36.  
  37. public ActionResult Bar()
  38. {
  39. var value = TempData["foo"] as string;
  40. // use the value here. If you need to pass it to the view you could
  41. // use ViewData/ViewBag (I can't believe I said that but I will leave it for the moment)
  42. return View();
  43. }
Add Comment
Please, Sign In to add comment