title: Sending a complex object as parameter to Asp.Net PageMethod
body: <p>I am trying to send an object created in JavaScript to an ASP.NET PageMethod. This object mirrors the properties of an existing custom business object, so i was hoping that i could pass a single object instead of a parameter for each property. I am getting an error "Unknown web method SavePart when attempting to use this method. </p>
  
  <p>Javascript:</p>
  
  <pre><code>function() {
      var pt = { Id: 1, Onhand: 20, LowPoint: 30, __type: 'Custom.Objects.Part'};
  
      $.ajax({
          type: 'POST',
          url: 'partlist.aspx/SavePart',
          data: JSON.stringify(pt),
          contentType: 'application/json; charset: utf-8;'
          dataType: 'json',
          success: function(results) { alert('Success!'); }
      });
  }
  </code></pre>
  
  <p>Code Behind:</p>
  
  <pre><code>&lt;WebMethod()&gt; _
  Public Shared Function SavePart(pt as Custom.Objects.Part) as Boolean
      Dim repo as new PartRepository()
      return repo.Save(pt)
  End Function
  </code></pre>
  
  <p>I am using another PageMethod which just accepts an int, and this works fine.</p>