I have not used it much, but from my understanding you should first install MVC 3 WebGrid before using it. And you do not want to customize the table in the view, but instead use it using the model attributes.
If I do this, I will do the following:
Create my custom attributes with which I would decorate my model to determine which properties are columns, which labels will be used for the column heading and everything you want to customize.
I will create a static class with a static method that takes an instance of the model, uses reflection to read the properties and your user attributes, and from there it spits out a WebGrid for you so you can use it in your view.
That’s how, but I’ll tell you why I won’t do it: in MVC you decorate your model for things like validation, and it’s wonderful and declarative. But when you define a grid, this is a very specific thing. Of course, you can use ViewModels, which are specific to the view, but I do not think that the layout layout configuration belongs to the model. The path of WebGrid or Telerik Grid to its work is already well declarative.
I short WebGrid and Telerik Grid already use best practices, offering declarative, smooth interfaces to determine the structure and behavior of tables. Each table is different, so it makes sense to define each table. You say “manually”, but this is far from the case, since grids do all the dirty work for you, you just tell her what you want (declarative programming).
Fabian nicollier
source share