问题描述
我使用EWS来开发我的电子邮件客户端。我发现,如果我存储在ITEMID视图状态会导致异常说道:
I am using EWS to develop my email client. I found that if I store ItemId in viewstate it will cause an exception says:
键入Microsoft.Exchange.WebServices.Data.ItemId'在大会'Microsoft.Exchange.WebServices,版本= 14.0.0.0,文化=中性公钥= 31bf3856ad364e35'未标记为可序列。
如果我存储 ITEMID
为字符串,如:
If I store ItemId
as string like:
ViewState["itemId"] = id.ToString();
,然后尝试投退,
and then try to cast back,
ItemId id = (ItemId)ViewState["itemId"];
它说,我无法从字符串转换为 ITEMID
。任何想法?
推荐答案
由于错误信息显示,除非它被标记为可序列化,你不能存储在视图状态的对象。
As the error message suggests, you can't store an object in viewstate unless it's marked as serializable.
综观文件这里,似乎ITEMID类有一个唯一ID属性,它是一个字符串和一个构造函数,它接受一个字符串'UNIQUEID'参数。
Looking at the documentation here, it seems that the ItemId class has a UniqueId property, which is a string, and a constructor which takes a string 'uniqueId' parameter.
所以,你可以储存UNIQUEID在ViewState中,并使用构造重新生成对象?
So, can you store the uniqueId in viewstate, and regenerate the object using the constructor?
这篇关于如何存储在视图状态的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!