2

I've implemented a functioning jqgrid in MVC using a style similiar to:

<script type="text/javascript">
    jQuery(document).ready(function(){ 
      jQuery("#list").jqGrid({
        url:'/Home/GridData/',
        datatype: 'json',
        mtype: 'GET',
        colNames:['Id','Votes','Title'],
        colModel :[
          {name:'Id', index:'Id', width:40, align:'left' },
          {name:'Votes', index:'Votes', width:40, align:'left' },
          {name:'Title', index:'Title', width:200, align:'left'}],
        pager: jQuery('#pager'),
        rowNum:10,
        rowList:[5,10,20,50],
        sortname: 'Id',
        sortorder: "desc",
        viewrecords: true,
        imgpath: '/scripts/themes/coffee/images',
        caption: 'My first grid'
      }); 
    }); 
</script>

from:

http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx

Here it is implemented mainly in the View.

However when trying to solved a populating edit dropdownlist from database issue I found:

http://www.trirand.net/demoaspnetmvc.aspx

In this solution they seem to do most of the grid setup implementation in the controller.

I would like to know which is best maybe from a best practices viewpoint. Thanks!

AnonyMouse
  • 18,108
  • 26
  • 79
  • 131
  • It seems to me that both solutions (free and commercial) contain the main parts of the implementation in *controller* actions. If you use solution of Phil Haack I recommend you to look as UPDATED part of [this answer](http://stackoverflow.com/questions/5500805/asp-net-mvc-2-0-implementation-of-searching-in-jqgrid/5501644#5501644) or download [the VS2008 demo project](http://www.ok-soft-gmbh.com/jqGrid/jqGridDemo.zip) or [the VS2010 demo project](http://www.ok-soft-gmbh.com/jqGrid/jqGridDemoVS2010.zip). Th demos are the updates of Phil's demo to new version of jqGrid. – Oleg Aug 16 '11 at 09:06

1 Answers1

0

jQuery is a JavaScript framework and jqGrid is made of jQuery.

So it should be handled in viewer. There is no way to handle jqGrid in controller technically.

But If you want to generate that in controller-side, you can generate that

in server-page dynamically.

jwchang
  • 10,584
  • 15
  • 58
  • 89