1

@{
var grid = new WebGrid(source: ViewBag.AllUsers,//在view Bag中我们有数据集来绑定rowsPerPage: 10);

    }
    @grid.GetHtml(
                 tableStyle: "gridtable",
        alternatingRowStyle: "even",

    columns: grid.Columns(
                    grid.Column("UserId", "Id"),
                    grid.Column("userName", "Name"),
                    grid.Column("City", "City"),
                    grid.Column("Designation","Designation"),
                    grid.Column("sal","Salary")
                   )            


                )
            )
4

1 回答 1

1

在您的控制器中放置这样的代码

 [HttpGet]
    public ActionResult View(Modelclass viewmodel)
    {
        List<Modelclass> employees = new List<Modelclass>();
        DataSet ds = viewmodel.GetAllAuthors();
        var empList = ds.Tables[0].AsEnumerable().Select(dataRow => new Modelclass{
           AuthorId = dataRow.Field<int>("AuthorId"),
            Fname = dataRow.Field<string>("FName"),
           Lname = dataRow.Field<string>("Lname")
        });
        var list = empList.ToList();



        return View(list);
    }

并且在视图中

@gd.GetHtml(tableStyle: "table",

            columns: gd.Columns(
                     gd.Column("AuthorId", "AuthorId"),
                     gd.Column("Fname", " Fname"),
                     gd.Column("Lname", "Lname", style: "description")

     )) 
于 2014-04-09T09:33:16.903 回答