title: JQGrid - Cannot call ASP.NET WebMethod but can with Ajax
body: <p>I am new to jqGrid and I have found it difficult to follow the documentation <a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3ajqgriddocs" rel="nofollow">jqGrid Documentation</a></p>
  
  <p>I cannot figure out how to call a WebMethod when setting up the JQGrid. I have been successful in making an Ajax call to get the data and then setting up the JQGrid with local data. I think its an extra step in the setup process and that I should be able to provide the path to the webmethod using the url property.</p>
  
  <p>The editurl property is the same way. I am never actually receiving the post to the server.</p>
  
  <p><strong>Original Code</strong></p>
  
  <p><strong>Attempted JQGrid Setup</strong></p>
  
  <pre><code>
  function GetData()
  {
      $('#list').jqGrid({
          type: "POST",
          url: "Default.aspx/GetUsersJSON",
          datatype: "json",
          height: 250,
          colName: ['Username', 'Email'],
          colModel: [
                  ...
      }).jqGrid(
                  'navGrid',
                  '#pager',
                  {
                      edit: true,
                      add: true,
                      del: true
                  });
  }
  </code></pre>
  
  <p><strong>WebMethod</strong></p>
  
  <pre><code>
  
          [WebMethod]
          public static string GetUsersJSON()
          {
              var users = new List();
              using(UserAdministrationSandboxDataContext uasd = new UserAdministrationSandboxDataContext())
              {
                  users = uasd.GetUserList();                
              }
              JavaScriptSerializer serializer = new JavaScriptSerializer();
              return serializer.Serialize(users); 
  
          }
  </code></pre>
  
  <p><strong>Current Code</strong></p>
  
  <p>I got it working correctly now, but I still have one final question. Why did I have to set the 'repeatitems: false' in order to display the content?</p>
  
  <p>Some of the caveats to get this to work include the different ways to setup the ajax request.</p>
  
  <p>(Ajax: type) is (jqgrid : mtype)
  (Ajax: contentType) is (jqgrid : ajaxGridOptions: { contentType:  })</p>
  
  <p>And finally understanding the documentation from the documentation on how to setup the JSONReader.</p>
  
  <p>Hope this helps others and thanks Oleg for all your help.</p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>
  
  function GetUserDataFromServer()
  {
      $('#list').jqGrid({
          url: "Default.aspx/GetUsersJSON",
          mtype: 'POST',        
          ajaxGridOptions: { contentType: "application/json" },
          datatype: "json",
          serializeGridData: function (postData)
          {
              return JSON.stringify(postData);
          },
          jsonReader: {
              root: function (obj) { return obj.d; },
              page: function (obj) { return 1; },
              total: function (obj) { return 1; },
              records: function (obj) { return obj.d.length; },
              id:'0',
              cell:'',
              repeatitems: false            
          },
          datatype: "json",
          height: 250,
          colName: ['Username', 'Email'],
          colModel: [
                  {
                      name: 'Username',
                      index: 'Username',
                      width: 100,
                      editable: true
                  },
                  {
                      name: 'Email',
                      index: 'Email',
                      width: 220,
                      editable: true
                  },
                  {
                      name: 'IsLockedOut',
                      index: 'IsLockedOut',
                      width: 100,
                      editable: true,
                      edittype: 'checkbox'
                  }
          ],
          caption: "Users"
      })
  }
  </code></pre>
  
  <p><strong>Web Method</strong></p>
  
  <pre><code>
          [WebMethod]
          [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
          public static List GetUsersJSON()
          {
              using (UserAdministrationSandboxDataContext uasd = new UserAdministrationSandboxDataContext())
              {
                  return uasd.GetUserList();
              }
          }
  </code></pre>
  
  <p><strong>One JSON Object from the List</strong></p>
  
  <pre><code>
  {"__type":"UserAdministrationSandbox.UserData","PKID":"00000000-0000-0000-0000-000000000001","Username":"TestUser","ApplicationName":"Test","Email":"TestUser@test.com","Comment":"TestUser","Password":"D41D8CD98F00B204E9800998ECF8427E","PasswordQuestion":"Is this a blank Password?","PasswordAnswer":null,"IsApproved":true,"LastActivityDate":"\/Date(1298869200000)\/","LastLoginDate":"\/Date(1298869200000)\/","LastPasswordChangedDate":"\/Date(1298869200000)\/","CreationDate":"\/Date(1298869200000)\/","IsOnLine":false,"IsLockedOut":false,"LastLockedOutDate":"\/Date(1298869200000)\/","FailedPasswordAttemptCount":0,"FailedPasswordAttemptWindowStart":null,"FailedPasswordAnswerAttemptCount":null,"FailedPasswordAnswerAttemptWindowStart":null}
  </code></pre>