.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>