不能申请用[]索引类型为ICollection的的前pression [英] Cannot apply indexing with [] to an expression of type ICollection

查看:174
本文介绍了不能申请用[]索引类型为ICollection的的前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可有人请提供code来解决这个问题?

无法与适用[]索引到类型的前pressionICollection的

从本质上讲,我试图保存/从对象的集合绑定的值。

  @model MVC3.Models.Parent@ Html.EditorFor(型号=> model.Bs [0] .VAL)大众A级
{
    公众诠释名称{;组; }
    公共虚拟的ICollection< B> BS {搞定;组; }
}大众B级
{
    公众诠释的Val {获得;组; }
    公共虚拟A A {搞定;组; }
}


解决方案

的ICollection ,则没有顺序,以至于无法进行索引。

相反,你应该使用带有的IList℃的单独ViewModel类; T> 属性

Can someone please provide code to fix this error?

"Cannot apply indexing with [] to an expression of type 'ICollection'

Essentially, I'm trying to save/bind a value from a collection of objects.

@model MVC3.Models.Parent

@Html.EditorFor(model => model.Bs[0].Val) 

public  class A
{
    public int Name { get; set; }
    public virtual ICollection<B> Bs { get; set; }
}

public  class B
{
    public int Val { get; set; }
    public virtual A A { get; set; }
}

解决方案

ICollections are not ordered, so that cannot be indexed.

Instead, you should use a separate ViewModel class with IList<T> property.

这篇关于不能申请用[]索引类型为ICollection的的前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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