title: Simple jqgrid Delete in MVC
body: <p>I've been trawling across the web for answers, and maybe it's a case of it being more complicated than I expect (or I just don't understand the solutions), but I am looking for a way to simply delete a selected row from my jqgrid by clicking the trash icon.</p>
  
  <p>Currently my grid is being populated with Linq to SQL data.
  Here is my grid:</p>
  
  <pre><code>jQuery("#grid").jqGrid({
                       url: '&lt;%= ResolveUrl("~/Home/GetData") %&gt;',
                       datatype: "json",
                       mtype: 'GET',
                       postData: { DDLid: function () { return jQuery("#DDL option:selected").val(); } },
                       colNames: ['Col1', 'Col2'],
                       colModel: [
                          { name: 'Col1', index: 'Col1', width: 200, editable: false },
                          { name: 'Col2', index: 'Col2', width: 200, editable: false }
                          ],
                       jsonReader: {
                           repeatitems: false
                       },
                       rowNum: 10,
                       pager: jQuery('#gridpager'),
                       sortname: 'Type',
                       viewrecords: true,
                       sortorder: "asc",
                       caption: "Table"
                   }).navGrid('#gridpager', { del: true, add: false, edit: false, search: false }, {}, {}, {url: "Delete"});
  </code></pre>
  
  <p>Now the 'id' in post data is NOT the primary key in this table - I just need it to help populate the grid.
  What I would like to get is the selected row id and pass it to the Delete method, but I can't find any way to do that.</p>
  
  <p>I have tried using <code>jQuery("#grid").getGridParam('selrow')</code> in the postData but it always returns null.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Here is my delete method, for reference:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Delete(int DDLid) 
      {
          int row = Convert.ToInt32(/*I NEED THIS ID*/);
          var query = from x in _ctx.DataTable
                      where ((x.id == row))
                      select x;
          _ctx.DataTable.DeleteOnSubmit(query.Single());
          _ctx.SubmitChanges();
          return Json(true);
      }
  </code></pre>
  
  <p>This method is called and is fine, but I am getting the wrong id. I need the selected row's id. This breaks because the DDLid returns more than one row (since it is used to populate the grid).</p>
  
  <p>I hope that makes sense.</p>