我在字段中声明了一个字典,例如:
Dictionary<String, string[]> operationDetails = new Dictionary<string, string[]> { };
执行了一些操作,字典被存储回ViewState,如下所示:
ViewState.Add("operationDetails", operationDetails);
我现在想要读取此变量并将其存储回operationDetails
:
operationDetails = ViewState["operationDetails"];
然而,这使我无法将对象转换为字典的错误。我试过Convert.ToDictionary
但是这样的声明不存在。
如何将此视图状态读回变量?
答案 0 :(得分:2)
您必须将ViewState强制转换回原始DataType
$ wine red-063.exe -c -r -t Android-x86 myapp.r
答案 1 :(得分:0)
这就是为什么建议使用 ViewBag 而不是 ViewState 它可以帮助您避免视图中的重新转换
set in c# as ViewBag.operationDetails = operationDetails;
get in razor as operationDetails =ViewBag.operationDetails