📜  tempdata 序列化程序不能出错 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:50.499000             🧑  作者: Mango

代码示例1
//TempData uses Session, which itself uses IDistributedCache. IDistributedCache doesn't have the capability to accept objects or to serialize objects. As a result, you need to do this yourself, i.e.:

TempData["PopupMessages"] = JsonConvert.SerializeObject(_popupMessages);
//Then, of course, after redirecting, you'll need to deserialize it back into the object you need:

ViewData["PopupMessages"] = JsonConvert.DeserializeObject>(TempData["PopupMessages"]);