如何存储在视图状态的对象? [英] How to store an object in the viewstate?

查看:147
本文介绍了如何存储在视图状态的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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'未标记为可序列。

Type 'Microsoft.Exchange.WebServices.Data.ItemId' in Assembly 'Microsoft.Exchange.WebServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.

如果我存储 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.

综观文件<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.itemid_members(v=EXCHG.80).aspx\"相对=nofollow>这里,似乎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?

这篇关于如何存储在视图状态的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆