变量列的webgrid视图

时间:2016-05-10 22:56:33

标签: asp.net-mvc-5 webgrid

我试图在MVC5中的WebGrid中显示变量列。以下显示了代码段。但是,我不知道如何渲染列列并坚持下去。



public class gridmatx
{  public Grid Grid { get; set; }
}
public class Grid
{  public List<string> Columns { get; set; }
    public List<GridRow> Rows { get; set; }
}
public class GridRow
{  public string Label { get; set; }
    public List<decimal> Values { get; set; }
    public List<GridRow> ChildRows { get; set; }
}

//----- controller-------
   public ActionResult Index1()
    {   gridmatx g = new gridmatx();
        g.Grid = new Grid();
        g.Grid.Columns = new List<string> { "2011", "2012", "2013", "2014", "2015" };
        g.Grid.Rows = new List<GridRow>
        {   new GridRow { Label = "First", Values = new List<decimal> { 5M, 2M, 1M, 8M, 10M } },
            new GridRow { Label = "Second", Values = new List<decimal> { 2M, 2M, 4M, 8M, 9M } },
            new GridRow { Label = "Third", Values = new List<decimal> { 12M, 8M, 1M, 9M, 3M } }
        };
        return View(g);
   }
&#13;
    var grid = new WebGrid(Model.Grid.Rows, canSort: false, canPage: true, rowsPerPage: 5);
    <div>
        @{ 
            for (int i = 0; i < Model.Grid.Columns.Count; i++)
            {
                var index = i;
                @grid.GetHtml(columns:
                 grid.Columns
                 (  grid.Column("Label", "items"),
                     grid.Column(Model.Grid.Rows[i].Values[index], "columnX")
                     ), mode: WebGridPagerModes.Numeric);
            }
&#13;
&#13;
&#13;

我有一个&#34;标签&#34;列和可变数量的&#34;值&#34;列。 提前感谢您的帮助。

0 个答案:

没有答案