title: jquery.POST to MVC controller to return JSON
body: <p>I have created a following model</p>
  
  <pre><code>public class myModel
  {
      public int ID;
      public string Name;
      public int[] days;
  }
  </code></pre>
  
  <p>Then I created an action in a controller</p>
  
  <pre><code>[HttpPost]
  public ActionResult myCtrlAction(myModel thisModel)
  {
     if (ModelState.IsValid)
          {
              return Json(thisModel);
          }
          else
          {
              string errorMessage = "&lt;div class=\"validation-summary-errors\"&gt;"
                + "The following errors occurred:&lt;ul&gt;";
              foreach (var key in ModelState.Keys)
              {
                  var error = ModelState[key].Errors.FirstOrDefault();
                  if (error != null)
                  {
                      errorMessage += "&lt;li class=\"field-validation-error\"&gt;"
                       + error.ErrorMessage + "&lt;/li&gt;";
                  }
              }
              errorMessage += "&lt;/ul&gt;";
              return Json(new myModel { Name = errorMessage });  //just for now
          } 
     }
  </code></pre>
  
  <p>In my javascript I send the data using jQuery.post() as</p>
  
  <pre><code>$("#myBtn").click(function () {
  var mydata = {
            ID: $("#inputID").val(),
            Name: $("#inputName").val(),
            Days: $("#selectDays").select2("val")
         }
      var url = 'myController/myCtrlAction';  //definitly it was writtern as @Url.Action
      $.post(url, mydata, function(data) { alert(data); //which shows [object object] 
                       }, 'json');
   });
  </code></pre>
  
  <p>Now On request when I debug in Chrome I saw in headers as</p>
  
  <p><strong>Form Data</strong>
  ID: 5
  Name: SomeName
  Days[]: 6
  Days[]: 5</p>
  
  <p>In Response I got json format of my model as</p>
  
  <p><em><strong>{ID: "0", Name: "null", Days: "null"}</em></strong> it means my model state is valid but why its not having the values?</p>
  
  <p>Any body has any idea.  what I did wrong or do I miss something?</p>