//Controller:
ViewBag.User1 = "张三"; ViewData["User2"] = "李四"; TempData["User3"] = "王五"; HttpContext.Session.SetString("User4","赵六" ); Object User5 = "田七"; return View(User5);
// View
@model string
<h2>@ViewBag.User1</h2> <h2>@ViewData["User2"]</h2> <h2>@TempData["User3"]</h2> <h2>@Context.Session.GetString("User4")</h2> <h2>@Model</h2>
//在.net6中 使用session 需要注册服务才可以使用
标签:User5,Session,ViewBag,TempData,MVC,NET6,传值 From: https://www.cnblogs.com/YZQDXMN/p/17181348.html