You don't need to add the rows. They will be automatically generated when you call @grid.GetHtml()
.
This article shows you how to use the WebGrid
and even improve it to be safely typed, if you want to.
The minimum code to render a grid looks like this:
@{
var grid = new WebGrid(Model, defaultSort:"Name");
}
@grid.GetHtml()
Where Model
is an IEnumerable<T>
of objects, for example a List<T>
. (Well there is a little bit more than the minimun: this will sort the grid by Name
, and Name
must be a property of the enumerated object).
Of course you can "fine-tune" it, by defining columns, formats and so on.