更新时间:2023-02-25 19:14:23
public ActionResult Test() {
TempData["shortMessage"] = "MyMessage";
return RedirectToAction("Details", new { id = theId});
}
public ActionResult Details {
//now I can populate my ViewBag (if I want to) with the TempData["shortMessage"] content
ViewBag.TheMessageIs = TempData["shortMessage"].ToString();
return View();
}
您必须这样做,因为当您重定向到另一个活动/视图时,视图包会失去其值
You have to do it like this since the viewbag looses its value when you redirect to another active / view