title: How to pass complex type using json to ASP.NET MVC controller
body: <p>I have a View that allows a user to enter/edit data for a new Widget.  I'd like to form up that data into a json object and send it to my controller via AJAX so I can do the validation on the server without a postback.</p>
  
  <p>I've got it all working, except I can't figure out how to pass the data so my controller method can accept a complex Widget type instead of individual parameters for each property.</p>
  
  <p>So, if this is my object:</p>
  
  <pre><code>public class Widget
  {
     public int Id { get; set; }
     public string Name { get; set; }
     public decimal Price { get; set; }
  }
  </code></pre>
  
  <p>I'd like my controller method to look something like this:</p>
  
  <pre><code>public JsonResult Save(Widget widget)
  {
     ...
  }
  </code></pre>
  
  <p>Currently, my jQuery looks like this:</p>
  
  <pre><code>var formData = $("#Form1").serializeArray();
  
  $.post("/Widget/Save",
     formData,
     function(result){}, "json");
  </code></pre>
  
  <p>My form (Form1) has an input field for each property on the Widget (Id, Name, Price).  This works great, but it ultimately passes each property of the Widget as a separate parameter to my controller method.</p>
  
  <p>Is there a way I could "intercept" the data, maybe using an ActionFilterAttribute, and deserialize it to a Widget object before my controller method gets called?</p>