.NET6 MVC 传值的五种方式

//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 需要注册服务才可以使用

 

posted @ 2023-03-05 19:13  有追求的小码农  阅读(55)  评论(0)    收藏  举报