asp.net mvc传值方式

.cs文件中:

public IActionResult Index()
{
ViewBag.Test = "ViewBagTest";
ViewData["Test"] = "ViewDataTest";
TempData["Test"] = "TempDataTest";
HttpContext.Session.SetString("Test","SessionTest");
object model = "ModelTest";
return View(model);
}

 

.cshtml文件中:

@using Microsoft.AspNetCore.Http;
@model string
<h3>@ViewBag.Test</h3>
<h3>@ViewData["Test"]</h3>
<h3>@TempData["Test"]</h3>
@{
HttpContext context = this.Context;
string SessionValue = context.Session.GetString("Test");
}
<h3>@SessionValue</h3>
<h3>@Model</h3>

 

posted @ 2022-06-10 14:39  天天向上哦  阅读(44)  评论(0编辑  收藏  举报