title: AJAX & Web Api Post Method - How does it work?
body: <p>I am trying to write to my database using AJAX / Jquery and c#. Whenever I pass the parameter in to the C# code it shows as null. I am using the default template that visual studio generates when creating a controller class. Any help would be appreciated!</p>
  <p>NOte: This is a rest service that I am trying to call. (A regular ASP website... not MVC. Also, the GET Rest api works perfectly.)</p>
  <p>Jquery/AJAX:</p>
  <pre><code>var dataJSON = { &quot;name&quot;: &quot;test&quot; }
  
  $('#testPostMethod').bind(&quot;click&quot;, GeneralPost);
  function GeneralPost() {
      $.ajax({
          type: 'POST',
          url: '../api/NewRecipe',
          data:JSON.stringify(dataJSON),
          contentType: 'application/json; charset=utf-8',
          dataType: 'json'
      });
  }
  </code></pre>
  <p>C#</p>
  <pre><code>    //If I remove the [FromBody] Tag then when I click the button this method is never called.
      public void Post([FromBody]string name)
  
      {
  
      }
  </code></pre>
  <p>EDIT:</p>
  <p>I have adjusted my code slightly but am still encountering the same issue. To recap, It is loading the POST method, but it is passing in null.</p>
  <p>C#</p>
  <pre><code> public class RecipeInformation
      {
          public string name { get; set; }
  
      }
  
          public void Post(RecipeInformation information)
  
          {
  
          }
  </code></pre>
  <p>AJAX:</p>
  <pre><code>    var dataJSON = { information: { name: &quot;test&quot; } };
  
      $('#testPostMethod').bind(&quot;click&quot;, GeneralPost);
      console.log(dataJSON);
      function GeneralPost() {
          $.ajax({
              type: 'POST',
              url: '../api/NewRecipe',
              data: dataJSON,
              contentType: 'application/json; charset=utf-8',
          });
      }
  </code></pre>