Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Index()
- {
- ViewData["foo"] = "bar";
- return View();
- }
- <div>@ViewData["foo"]</div>
- public ActionResult Index()
- {
- ViewBag.foo = "bar";
- return View();
- }
- <div>@ViewBag.foo</div>
- public class MyViewModel
- {
- public string Foo { get; set; }
- }
- public ActionResult Index()
- {
- var model = new MyViewModel { Foo = "bar" };
- return View(model);
- }
- @model MyViewModel
- <div>@Html.DisplayFor(x => x.Foo)</div>
- public ActionResult Foo()
- {
- TempData["foo"] = "bar";
- return RedirectToAction("bar");
- }
- public ActionResult Bar()
- {
- var value = TempData["foo"] as string;
- // use the value here. If you need to pass it to the view you could
- // use ViewData/ViewBag (I can't believe I said that but I will leave it for the moment)
- return View();
- }
Add Comment
Please, Sign In to add comment