title: ASP.Net MVC 3 JQGrid
body: <p>After reading up on the JQGrid control, I decided it would be good to use it in one of my ASP.Net MVC 3 Web applications.</p>
  
  <p>Firstly I followed Phil Haacks tutorial <a href="http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx">http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx</a> which is all good. I then tried to implement something similar into my app, the only difference being, I use Linq To Entities.</p>
  
  <p>My View page has all the css and Jquery classes imported, then I have my JavaScript Function and table which holds the data</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  jQuery(document).ready(function () {
      jQuery("#list").jqGrid({
          url: '/Home/LinqGridData/',
          datatype: 'json',
          mtype: 'GET',
          colNames: ['equipmentID', 'categoryTitle', 'title'],
          colModel: [
        { name: 'equipmentID', index: 'equipmentID', width: 40, align: 'left' },
        { name: 'categoryTitle', index: 'categoryTitle', width: 40, align: 'left' },
        { name: 'title', index: 'title', width: 200, align: 'left'}],
          pager: jQuery('#pager'),
          width: 660,
          height: 'auto',
          rowNum: 10,
          rowList: [5, 10, 20, 50],
          sortname: 'Id',
          sortorder: "desc",
          viewrecords: true,
          imgpath: '/scripts/themes/coffee/images',
          caption: 'My first grid'
      });
  }); 
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;h2&gt;My Grid Data&lt;/h2&gt;
  &lt;table id="list" class="scroll" cellpadding="0" cellspacing="0"&gt;&lt;/table&gt;
  &lt;div id="pager" class="scroll" style="text-align:center;"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Then in my controller, I have the following method which is suppose to return the Json data</p>
  
  <pre><code>public ActionResult LinqGridData(string sidx, string sord, int page, int rows)
      {
          AssetEntities context = new AssetEntities();
  
          var query = from e in context.Equipments
                      select e;
  
          var count = query.Count();
  
          var result = new
          {
              total = 1,
              page = page,
              records = count,
              rows = (from e in query
                      select new
                      {
                          id = e.equipmentID,
                          cell = new string[]
                          {
                          e.equipmentID.ToString(),
                          e.Category.categoryTitle,
                          e.Department.title
                          }
  
                      }).ToArray()
          };
  
          return Json(result, JsonRequestBehavior.AllowGet);
  
      }
  </code></pre>
  
  <p>When I run this, the code falls over with the following error</p>
  
  <pre><code>LINQ to Entities does not recognize the method 'System.String ToString()' method
  </code></pre>
  
  <p>Does anyone know how to fix this error? And also, am I doing this the correct way, or should I be doing it a different way from the Phil Haack explanation since he is using Linq to SQL?</p>
  
  <p>Any feedback would be much appreciated.</p>
  
  <p>Thanks Folks.</p>