title: JSON to MVC Object from an Ajax Post
body: <p>I have this json array-ish variable which gets values from a table:</p>
  
  <pre><code>var data = { "Model": [] };
  $(".student-grade-data-row").each(function () {
      data.Model.push({
          'subjectId' : currentSubjectId,
          'studentId': $(this).attr('id'),
          'grade1' : $(this).find(".grade-select").val(),
          'mult' : $(this).find(".mult-select").val(),
          'subject': $(this).find(".topic-input").val(),
      });
  });
  </code></pre>
  
  <p>It was made to resemble a MVC class called <code>grade</code></p>
  
  <pre><code>public partial class grade
  {
      public int id { get; set; } //auto-set
      public int subjectId { get; set; }
      public string studentId { get; set; }
      public int grade1 { get; set; }
      public int mult { get; set; }
      public string subject { get; set; }
      public System.DateTime date { get; set; } //auto-set
  }
  </code></pre>
  
  <p>Now in the perfect world, I would like to have the values inside the <strong>data</strong> variable to be send into my controller like this:</p>
  
  <pre><code>$.ajax({
      url: '/Ajax/SendGrades',
      data: JSON.stringify(data),
      contentType: "application/json; charset=utf-8",
      success: function (dt) {
          console.log(dt);
      }
  });
  </code></pre>
  
  <p>And there I could pick it up, and serialize it as a proper object list.</p>
  
  <p>The problem isI cannot even get a glimpse of what really am I sending to the controller and how possibly could I link it to the object.</p>
  
  <p>I tried making the function take an agrument of type <code>List&lt;grade&gt; Model</code>, but It would keep telling me the value is null.</p>
  
  <hr>
  
  <p>I tried using some basic serialization but cant get it to work either. The code</p>
  
  <pre><code>public ActionResult SendGrades(JsonResult Model)
  {
      List&lt;grade&gt; g = new List&lt;grade&gt;();
      DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(grade));
      g = (List&lt;grade&gt;)serializer.ReadObject(Model);
      return Content("Hi");
  }
  </code></pre>
  
  <p>Gives me an error saying</p>
  
  <blockquote>
    <p>Cannot convert from System.Web.Mvc.JsonResult to System.IO.Stream</p>
  </blockquote>
  
  <p>What would be the proper way to do this so I could later safely store the values in my database?</p>
  
  <p>I'm fairly new to this type of work so I apologize for any noob-ism.
  Any help would be great here.</p>