原文出处我只是跟老师做笔记
https://www.bilibili.com/video/BV1xB4y1T7i2?p=5
控制器
base.ViewBag.User1="张三";
base.ViewData["User2"]="李四";
base.TempData["User3"]="王五";
base.HttpContext.Session["User4"]="赵六";
object model = "Richard";
return View(model);
view
@model string
<h3>ViewBag.User1=@base.ViewBag.User1</h3>
<h3>ViewData.User2=@base.ViewData["User2"]</h3>
<h3>TempData.User3=@base.TempData["User3“]</h3>
<h3>Session.User4=@HttpContext.Current.Session["User4"]</h3>
<h3>model.User5=@model </h3>
结果
异常情况:
同一个视图,如果key一样,后面值会覆盖前面值
不同视图,return到其他视图部分值会丢失