【发布时间】:2015-11-06 04:09:32
【问题描述】:
我得到IEnumerable<object> 列表到Create_Brochure 控制器方法如下
所以我想保留这个对象列表并在Create_Brochure_PDF控制器方法中重用
所以我在 create session 中添加了以下几行
在Create_Brochure控制器方法中
IEnumerable<ProductsPropertiesVM> newmodel = model;
Session["TemplateData"] = newmodel;
为了在Create_Brochure_PDF 控制器方法中使用该会话,我在Create_Brochure_PDF 控制器方法中添加了以下几行
IEnumerable<ProductsPropertiesVM> newmodel = Session["TemplateData"] as IEnumerable<ProductsPropertiesVM>;
但我在Create_Brochure_PDF 控制器方法中为这个新模型获得了null
我需要知道如何为IEnumerable<object> 列表定义一个会话并在另一个方法中正确地重用它。
【问题讨论】:
-
试试这个
IEnumerable<ProductsPropertiesVM> newmodel =(IEnumerable<ProductsPropertiesVM>)Session["TemplateData"]; -
同样的事情,除了如果强制转换失败而不是 null,你会得到一个 InvalidCastException。
-
@EricJ。一旦我调试,我可以看到它的
null不是我认为的演员问题 -
@kez:如果你的演员使用
as语法无效,表达式产生null。 -
@EricJ。一旦我尝试您的方法
'object' does not contain a definition for 'Cast' and the best extension method overload 'Queryable.Cast<ProductsPropertiesVM>(IQueryable)' requires a receiver of type 'IQueryable',就会出现这种编译时错误
标签: c# asp.net-mvc session ienumerable generic-list