我想将4个成员的Tuple传递给View。
控制器:
PGOrders pGOrder = db.PGOrders.Find(id);
int imgID = pGOrder.imageID;
PGOrderImages pGorderImages = db.PGOrderImages.Find(imgID);
PGAccountDatas account = db.PGAccountDatas.Where(a => a.PGAccountDataID == pGOrder.ordererID).FirstOrDefault();
var offs = db.PGOffers.Where(o => o.orderID == pGOrder.PGOrderID);
return View(Tuple.Create(pGOrder, pGorderImages, account, offs));
查看:
@using projectname.Models
@model Tuple<PGOrders, PGOrderImages, PGAccountDatas, IQueryable<PGOffers>>
@foreach (var item in Model.Item4){
<text><p> some item property</p></text>
}
问题与foreach循环一致。
Exception Details: System.InvalidCastException: Object must implement IConvertible.
我试图改变
var offs = db.PGOffers.Where(o => o.orderID == pGOrder.PGOrderID);
至
var offs = db.PGOffers.Where(o => o.orderID == pGOrder.PGOrderID).ToList();
并在View中更改
IQueryable<PGOffers>
IEnumerable<PGOffers>
但它没有帮助。
pGOrder,pGorderImages,account是指定的类对象。
问题是:
如何将类对象列表作为元组成员传递?
答案 0 :(得分:0)
你必须转换为可枚举,如下所示:
var offs = db.PGOffers.Where(o => o.orderID == pGOrder.PGOrderID).AsEnumerable();
然后将您的模型设置为:
@model Tuple<PGOrders, PGOrderImages, PGAccountDatas, IEnumerable<PGOffers>>