views:

420

answers:

2

Hi

I'm creating a search page, the page has a form that is being submitted using Ajax, after the search is performed I want to display a grid with the results.

My question is, should I create the grid when the page loads and then fill it with the data after the search is performed, or create the grid on the server when the search is performed and then just append the grid to the page.

I was thinking on creating a helper method to render the grid and invoking it from the controller after it gets the results, then returning the result of the helper method and appending it to the page, but this might be against MVC architecture (I'm defining UI on the controller).

What approach should I take?

Thanks

+3  A: 

for the grid creation, you can have a look at MVCContrib grid helper

Gregoire
mxmissile
+2  A: 

You could use jqGrid (http://www.trirand.com/blog/) or Flexigrid (http://www.flexigrid.info/) and load data with ajax and json. You submit search form with ajax, controller returns JsonResult, and then you load it into grid in callback. It is easy to implement and gives you additional functionalities (sorting and much, much more). Here you have some demos:

http://trirand.com/jqgrid/jqgrid.html

LukLed
ThanksI'm planning on using jqGrid, but my question was more architecture-related. I want to know if the best approach is creating the grid on the view or the controller.
willvv
Controller should prepare data for view, but not construct whole view. You can return Json in controllers action or you can return partial view result which draws whole grid. Controller will provide it with data from model. If you use partial view to draw whole grid, oyu can use it in more places.
LukLed