title: How to pass the full Model from view to controller via jquery in a MVC c# application
body: <p>I have a list of checkbox's and textbox's. I want to let the user add items to the list via a partial view modal popup. </p>
  
  <p>After the user adds an item to the list, if any items on the original view have values in them, I want them preserved, and the page refreshed with the added items.</p>
  
  <p>I want to send the full model back to the controller from the original view, I can then just add the new items to that model and pass the model back to the original page and have all my values preserved.</p>
  
  <p>I could grab all the values and pass them via loops and such in javascript (very tedious), but I think the full model would be the easiest way.</p>
  
  <p>I sawe a link from Laviak on a post from <a href="https://stackoverflow.com/questions/1518417/how-to-send-a-model-in-jquery-ajax-post-request-asp-net-mvc">here</a>..., but I can't get it to work.</p>
  
  <p>it states....
  If you need to send the FULL model to the controller, you first need the model to be available to your javascript code.</p>
  
  <p>In our app, we do this with an extension method:</p>
  
  <pre><code>public static class JsonExtensions 
  { 
      public static string ToJson(this Object obj) 
      { 
         return new JavaScriptSerializer().Serialize(obj); 
     } 
  } 
  </code></pre>
  
  <p>On the view, we use it to render the model:</p>
  
  <pre><code>&lt;script type="javascript"&gt; 
    var model = &lt;%= Model.ToJson() %&gt; 
  &lt;/script&gt; 
  </code></pre>
  
  <p>You can then pass the model variable into your $.ajax call.</p>
  
  <p>Has anyone got this to work??? </p>
  
  <p>Thanks
  Bill</p>