views:

223

answers:

4

I don't want to make this into a "which is better... MVC or WebForms" type of question. Im sure that has been asked a bunch of times here already.

My Question: If I am building a MVC web project, why should I not use an ASP.NET datagrid control on one of my "Views" .aspx pages?

+4  A: 

The control relies on Viewstate which isn't available in MVC. In addition, all the behavior is predicated on the WebForms event and postback model which you'd have to recreate in MVC to get them to work. You could search for alternate, MVC-friendly grids (perhaps jQuery-based). I know that Telerik has released a set of MVC controls under open source that might be helpful to you.

tvanfosson
A: 

The datagrid control depends on postback events which does not fit into the MVC way of thinking (the postback goes to the page code behind rather than the controller). You could use one without any postback features, i believe, but you may as well craft something directly.

Pharabus
A: 

Because the ASP.NET DataGrid / GridView has too much responsibility to fit into the MVC pattern. You'll have to add some code-behind to your view to databind the grid - code that belongs in the controller.

Anything that uses postback won't work with MVC, so the DataGrids paging and sorting won't be any good to you. So there really isn't any benefit to using it.

If you're looking for a flexible grid 'control' (MVC prefers the term HTML Helper), the MvcContrib grid is pretty good.

richeym
+2  A: 

you can't use web forms controls in MVC because they depend on view state. Use the data grid of the Mvc Controls toolkit instead. It has paging, insert delete and update capabilities and it is completely templated (you can shap it as you like). Look at it here

marco