title: Value cannot be null. Deserialize Object Json
body: <p>I am having issues deserializing this json string to a c# object.  I have tried numerous different configuration of the model and i have tried to serialize the code and let the mvc value providers to do this, but i can't get it to work.....  So I am sending this JSON string to my controller and then putting it into an object and then creating the correct object to throw it in my database.</p>
  
  <pre><code>[ArgumentNullException: Value cannot be null.
  Parameter name: value]
     Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) +162
     Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings settings) +66
     InSight.Controllers.QuestionController.CreateSimpleQuestion(String json) +25
  </code></pre>
  
  <p>This is the string before i send it to my controller:</p>
  
  <pre><code>var data = JSON.stringify({
              QuestionTitle: title,
              Keywords: key,
              Description: desc,
              Comments: comments,
              QuestionType: type,
              choices: {
                  DisplayText: text,
                  OrderNumber: order,
                  is_correct:is_correct
              }
          });
  </code></pre>
  
  <p>This is the controller method:</p>
  
  <pre><code>public ActionResult CreateSimpleQuestion(string json)
      {
          SimpleQuestion temp = JsonConvert.DeserializeObject&lt;SimpleQuestion&gt;(json);
          Question question = new Question();
          question.QuestionTitle = temp.QuestionTitle;
          question.QuestionType = temp.QuestionType;
          question.Keywords = temp.Keywords;
          question.is_counted = true;
          question.DateCreated = DateTime.Now;
          question.Comments = temp.Comments;
          question.QuestionType = "Simple";
          db.Questions.Add(question);
  
          db.QuestionChoices.Add(temp.choices.First());
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>and this is the model:</p>
  
  <pre><code>public class SimpleQuestion
      {
              public int QuestionId { get; set; }
  
              public string QuestionTitle { get; set; }
  
              public DateTime DateCreated { get; set; }
  
              public string QuestionType { get; set; }
  
              public string Keywords { get; set; }
  
              public bool is_counted { get; set; }
  
              public string Description { get; set; }
  
              public string Comments { get; set; }
  
          public List&lt;QuestionChoices&gt; choices { get; set; }
      }
  </code></pre>
  
  <p>finally, this is the actual string of data that is getting passed: </p>
  
  <pre><code>{"QuestionTitle":"This is the Question Title",
  "Keywords":"Blue pony, sharks",
  "Description":"This is the description field.",
  "Comments":"No comment has been left.",
  "choices":{
      "DisplayText":"Will it rain tomorrow?",
      "OrderNumber":"1","is_correct":false
    }
  } 
  </code></pre>
  
  <p><strong>Solution</strong>
  Change the JS where <code>data</code> was defined to the following:</p>
  
  <pre><code>            var data = {
              "QuestionTitle": title,
              "Keywords": key,
              "Description": desc,
              "Comments": comments,
              "QuestionType": type,
              "choices": {
                  "DisplayText": text,
                  "OrderNumber": order,
                  "is_correct":false
              }
          };
  </code></pre>