Asp.net mvc 4 EditorForModel不使用ICollection MVC 4
我们有以下型号:Asp.net mvc 4 EditorForModel不使用ICollection MVC 4,asp.net-mvc-4,entity-framework-4,Asp.net Mvc 4,Entity Framework 4,我们有以下型号: public class Sample { public int SampleId { get; set; } public int ToTestId { get; set; } public int Name { get; set; } public virtual ICollection<SampleCondition> Child_SampleConditions { get; set; } } 它只返回[0].Conditi
public class Sample
{
public int SampleId { get; set; }
public int ToTestId { get; set; }
public int Name { get; set; }
public virtual ICollection<SampleCondition> Child_SampleConditions { get; set; }
}
它只返回[0].ConditionValue,但不返回子\u SampleConditions[0].ConditionValue
请告知
谢谢。而不是:
O => sampleConditions[0].ConditionValue
写:
O => O.Child_SampleConditions[0].ConditionValue
编辑:
使用IList创建ViewModel,因为ICollection无法编制索引:
public class SampleVM
{
public int SampleId { get; set; }
public int ToTestId { get; set; }
public int Name { get; set; }
public virtual IList<SampleCondition> Child_SampleConditions { get; set; }
}
参考链接:否,不起作用。它给出编译时错误:错误4无法对“System.Collections.Generic.ICollection”类型的表达式应用带[]的索引。您无法通过创建视图模型为ICollection使用IList编制索引。我认为我无法更改模型。它们是由建筑师设计的。将ICollection更改为IList是否会产生任何后果?您必须创建一个特定于视图的视图模型,而不是您的数据模型,如何将我的数据模型分配给视图模型?
O => O.Child_SampleConditions[0].ConditionValue
public class SampleVM
{
public int SampleId { get; set; }
public int ToTestId { get; set; }
public int Name { get; set; }
public virtual IList<SampleCondition> Child_SampleConditions { get; set; }
}