Asp.net mvc .NET MVC-生成复杂列表

Asp.net mvc .NET MVC-生成复杂列表,asp.net-mvc,Asp.net Mvc,如果我不太懂这个词,我很抱歉。我知道如何在PHP中做到这一点,但不知道如何在.NETMVC中做到这一点 简而言之,我需要从多个表中获取类别。我知道在PHP中,我会创建一个新对象,然后向该对象添加一个数组。例如,我需要能够构建一些东西,这样我就可以将其返回到视图并对其进行迭代。比如: categoryType1 subcategoryType1 (also has ID, name, description) subsubCategoryType1 (also has I

如果我不太懂这个词,我很抱歉。我知道如何在PHP中做到这一点,但不知道如何在.NETMVC中做到这一点

简而言之,我需要从多个表中获取类别。我知道在PHP中,我会创建一个新对象,然后向该对象添加一个数组。例如,我需要能够构建一些东西,这样我就可以将其返回到视图并对其进行迭代。比如:

categoryType1 
    subcategoryType1 (also has ID, name, description)
        subsubCategoryType1 (also has ID, name, description)
        subsubCategoryType2 (also has ID, name, description)
        subsubCategoryType3 (also has ID, name, description)
    subcategoryType2 (also has ID, name, description)
        subsubCategoryType1 (also has ID, name, description)
        subsubCategoryType2 (also has ID, name, description)
        subsubCategoryType3 (also has ID, name, description)
categoryType2
    subcategoryType1 (also has ID, name, description)
        subsubCategoryType1 (also has ID, name, description)
        subsubCategoryType2 (also has ID, name, description)
        subsubCategoryType3 (also has ID, name, description)
    subcategoryType2 (also has ID, name, description)
        subsubCategoryType1 (also has ID, name, description)
        subsubCategoryType2 (also has ID, name, description)
        subsubCategoryType3 (also has ID, name, description)
现在,我少了一个关卡,所以看起来是这样的:

在模型中:

public class LayoutViewModel
{
    public int ID { get; set; }
    public string Category { get; set; }
    public IEnumerable<string> OutcomeType { get; set; }
    public string Identifier { get; set; }
}

但上面的例子只是其中之一。我需要多次执行此操作,但仍然将它们作为一个对象(列表?)一起返回到视图中。

那么,您到底在坚持什么?问题是什么?如何将多个查询的累积返回到视图。因此,如果我说一个像var category1这样的查询,我可以将多个category1添加到其他类型的变量中,并将其返回到视图中。不确定这是否有意义。只需将
列表
数组[]
返回到您的视图中即可?这是一个,它是pre-Razor,但概念相同。下面是
public PartialViewResult _Sidebar()
    {
        var category1 = db.Category1.Where(oa => oa.Category != "")
            .GroupBy(oa => oa.Category).Select(oa => new LayoutViewModel
            {
                Category = oa.Key,
                Identifier = oa.Key.Replace(" ", "-").ToString(),
                SubCategory = oa.Select(y => y.SubCategory).Distinct()
            });
        return PartialView("_Sidebar", category1);
    }