C# asp.net-mvc如何在迭代时添加对象(Foreach)

C# asp.net-mvc如何在迭代时添加对象(Foreach),c#,asp.net-mvc,C#,Asp.net Mvc,我有这样的看法 @(Html.Kendo().Chart() .Name("chart-store") .Title("Percentage Store Rent") .Legend(legend => legend .Position(ChartLegendPosition.Bottom) ) //.SeriesColors(new string[] { "#42a7ff", "#66

我有这样的看法

@(Html.Kendo().Chart()
        .Name("chart-store")
        .Title("Percentage Store Rent")
        .Legend(legend => legend
            .Position(ChartLegendPosition.Bottom)
        )
        //.SeriesColors(new string[] { "#42a7ff", "#666666", "#999999", "#cccccc", "#013A5E" })
        .Series(series => {
            series.Pie(new dynamic[] {
                new {category = "Living Room",value = 35},
                new {category = "Dinning Room",value = 25},
                new {category = "Study Room",value = 20},
                new {category = "Bedroom",value = 10},
                new {category = "Outdoor",value = 10}                
            })
            .Labels(labels => labels
                .Visible(true)
                .Position(ChartPieLabelsPosition.OutsideEnd)
                .Template("#= category # - #= kendo.format('{0:P}', percentage)#")
                .Background("transparent")
            );
        })
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Template("#= category # - #= kendo.format('{0:P}', percentage) #")
        )
    )
饼图数据仍然是静态的。我想从数据库中获取数据。。我已经完成了下面的代码。但只给出一行数据

查看

@(Html.Kendo().Chart()
        .Name("chart-store")
        .Title("Percentage Store Rent")
        .Legend(legend => legend
            .Position(ChartLegendPosition.Bottom)
        )
        //.SeriesColors(new string[] { "#42a7ff", "#666666", "#999999", "#cccccc", "#013A5E" })
        .Series(series => {
            series.Pie(new dynamic[]{@g**.app.web.Controllers.Tran******Controller.GetPieChartByRoom()})
            .Labels(labels => labels
                .Visible(true)
                .Position(ChartPieLabelsPosition.OutsideEnd)
                .Template("#= category # - #= kendo.format('{0:P}', percentage)#")
                .Background("transparent")
            );
        })
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Template("#= category # - #= kendo.format('{0:P}', percentage) #")
        )
    )
控制器

public static object GetPieChartByRoom() {
            List<string> mHBM = new List<string>();
            mHBM.Add(mcHBM_SALES);
            mHBM.Add(mcHBM_BusinessPartner);
            mHBM.Add(mcHBM_Employee);
            mHBM.Add(mcHBM_LIST);
            mHBM.Add(mcHBM_GeneralListType);
            ISession voISession = NHibernateSession.OpenSession(mHBM);

            var getRoom = voISession.QueryOver<Lists>().Where(w=>w.Type==17).List();
            var voTable = new object();
            foreach (var ListRoom in getRoom)
            {
                var RoomCount = voISession.QueryOver<SalesAgreementDetail>().Where(w => w.Room == ListRoom.ListID).RowCount();
                voTable = new { category = ListRoom.ListName, value = RoomCount };
            }

            return voTable;        
        }
公共静态对象GetPieChartByRoom(){
List mHBM=新列表();
mHBM.Add(mcHBM_销售);
mHBM.Add(mcHBM_业务伙伴);
mHBM.Add(mcHBM_员工);
mHBM.Add(mcHBM_列表);
mHBM.Add(mcHBM_GeneralListType);
ISession voISession=NHibernateSession.OpenSession(mHBM);
var getRoom=voISession.QueryOver().Where(w=>w.Type==17.List();
var voTable=新对象();
foreach(getRoom中的var列表室)
{
var RoomCount=voISession.QueryOver().Where(w=>w.Room==ListRoom.ListID).RowCount();
voTable=new{category=ListRoom.ListName,value=RoomCount};
}
返回表;
}
感谢您的关注,并为我的英语不好而道歉:D

var voTable = new object();
foreach (var ListRoom in getRoom)
{
  var RoomCount = voISession.QueryOver<SalesAgreementDetail>().Where(w => w.Room == ListRoom.ListID).RowCount();
  voTable = new { category = ListRoom.ListName, value = RoomCount };
}

return voTable; 

发布完整的代码列表的名称,我想你应该像foreach(列表室中的var room)一样使用。谢谢你的回复,我已经更新了帖子。。你能帮我纠正一下吗。我的错在哪里?
var voTable = new List<object>();   //changes here
foreach (var ListRoom in getRoom)
{
  var RoomCount = voISession.QueryOver<SalesAgreementDetail>().Where(w => w.Room == ListRoom.ListID).RowCount();
  voTable.Add(new { category = ListRoom.ListName, value = RoomCount }); //changes here
}

return voTable;