您的当前位置:首页正文

asp.net mvc 传值的几种方式

2024-11-29 来源:个人技术集锦
//后端代码
public IActionResult Index()
{
    ViewBag.User1 = "张三";
    ViewData["User2"] = "李四";
    TempData["User3"] = "王五";
    HttpContext.Session.SetString("User4","赵六");
    object User5 = "田七";
    return View(User5);
}

//前端代码
@model String
<h2>User1=@ViewBag.User1</h2>
<h2>User2=@ViewData["User2"]</h2>
<h2>User3=@TempData["User3"]</h2>
<h2>User4=@Context.Session.GetString("User4")</h2>
<h2>User5=@Model</h2>

显示全文