1.ViewBag
2.ViewData
3.TempData
4.Session
5.model
1.当ViewBag与ViewData的key相同时,后者会覆盖前者
2.TempData和Session传值,跳转到其他方法后,热仍然可以获取到值—TempData其实是通过Session来实现的
3.model传值不要把数据类型定义成一个String类型,因为有重载支持 返回视图的名字
Controller中的代码:
base.ViewBag.User = "张三"; base.ViewData["user2"] = "李四"; base.TempData["user3"] = "王五"; base.HttpContext.Session["user6"] = "赵六"; object model2 = "this is model"; return View(model2);
View中的代码
@model string <h2>@base.ViewBag.User</h2> <h2>@base.ViewData["user2"]</h2> <h2>@base.TempData["user3"]</h2> <h2>@HttpContext.Current.Session["user6"]</h2> <h2>@Model</h2>