-3
として、私はモデルの定義を持っている:私はちょうど最初のレベルのみを取得し、このリストに値を追加する必要がありますが、次のコードを使用してmvc 4のリストに値を追加するには?
a)Redbook
a.1) Wedding
a.1.1) Christian
.
.
a.2)Baptism
b)Florenta
のようなサブ項目のn個があるかもしれません
public class CMBCategory
{
public int ID { get; set; }
public string Name { get; set; }
public List<CMBCategory> children = new List<CMBCategory>();
}
サブ製品の:ここで
foreach (var items in lstcatlist)
{
CMBCategory cmb = new CMBCategory();
cmb.ID = items.FirstOrDefault().catid;
cmb.Name = items.FirstOrDefault().title;
foreach (var item1 in items)
{
if (item1.parent == 0)
{
cmb.children.Add(new CMBCategory() { ID = item1.prod_id, Name = item1.desc });
}
}
lstmain.Add(cmb);
}
var lstcatlist = (from s in context.M_ProductCategory
join p in context.M_CategoryDetails on s.ID equals p.CategoryID
select new
{
catid = s.ID,
title = s.Title,
prod_id = p.ID,
parent = p.ParentID,
desc = p.Description
}).GroupBy(x => x.catid).ToList();
を使用する必要がある場合これは、理由は私のループ構造のため、ループn個のサブ製品の数に正しい構造を見つける方法を提供してくださいすることができます'lstcatlist'にあり、そのモデルは何ですか? –
@Stephen Muecke List lstmain = newリスト(); –
neethu
No - again - 'lstcatlist'には何があり、そのモデルは何ですか? –