title: Ajax POST not posting model to the controller in asp.net core 6
body: <p>I am trying to POST data to my controller from an event raised from Kendo dialog. But, the model is always coming as null. I tried various steps which were mentioned in StackOverflow itself, but none of them works.</p>
  <p><strong>My Ajax call</strong></p>
  <pre><code>function onSubmit(e) {
            
             var myModel={
                    Id:0,
                    RoleNameEn:$('#UserRolePopup').find('#RoleNameEn')[0].value,
                    RoleNameAr:$('#UserRolePopup').find('#RoleNameAr')[0].value,
                    IsActive:$('#UserRolePopup').find('#IsActive')[0].value,
                    CreatedBy:0,
                    CreatedDate:&quot;&quot;,
                    ModifiedBy:0,
                    ModifiedDate:&quot;&quot;
             };
  
             $.ajax({
                type: &quot;POST&quot;,
                url: &quot;@Url.Action(&quot;Delete&quot;, &quot;UserRole&quot;)&quot;, //'/UserRole/Create'
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(myModel) ,
                success: function (result) {
                  console.log(result);
                },
                error: function (result, status) {
                  console.log(result);
                }
              });
  
          }
  </code></pre>
  <p><strong>My HTML</strong></p>
  <pre><code>&lt;div id=&quot;example&quot;&gt;  
      @(Html.Kendo().Dialog()
      .Name(&quot;dialog&quot;)
      .Title(&quot;Add/Edit User Role&quot;)
      .Content(&quot;&lt;div id='UserRolePopup'&gt;  &lt;div class='form-group; k-content'&gt; &lt;label for='RoleNameEn'&gt;User role English&lt;/label&gt;    &lt;input type='text' class='form-control' id='RoleNameEn' placeholder='Role name in english'/&gt;      &lt;/div&gt; &lt;div class='form-group'&gt;    &lt;label for='RoleNameAr'&gt;User role Arabic&lt;/label&gt;    &lt;input type='text' class='form-control' id='RoleNameAr' placeholder='Role name in Arabic'&gt;      &lt;/div&gt;  &lt;div class='form-check'&gt;        &lt;input class='form-check-input' type='checkbox' value='' id='IsActive'&gt;    &lt;label class='form-check-label' for='IsActive'&gt;Is Active&lt;/label&gt;  &lt;/div&gt; &lt;/div&gt;&quot;)
      .Width(400)
      .Modal(true)
      .Actions(actions =&gt;
      {
      actions.Add().Text(&quot;Cancel&quot;);
      actions.Add().Text(&quot;Submit&quot;).Primary(true).Action(&quot;onSubmit&quot;);
      })
      .Events(ev =&gt; ev.Close(&quot;onClose&quot;).Open(&quot;onOpen&quot;))
      )
  &lt;/div&gt;
  </code></pre>
  <p>Now the data captured is passed to the controller.
  <a href="https://i.stack.imgur.com/DnDLr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DnDLr.png" alt="enter image description here" /></a></p>
  <p>You can see the value is getting passed to the controller.</p>
  <p><strong>My Controller</strong></p>
  <pre><code>[HttpPost]
          public JsonResult Delete([FromBody] UserRoleDTO userRoleDTO)
          {
              return new JsonResult(userRoleDTO);
          }
  </code></pre>
  <p><strong>My <code>Program.cs</code> file</strong></p>
  <pre><code>builder.Services.AddMvc()
             .AddNewtonsoftJson(options =&gt;
             options.SerializerSettings.ContractResolver =
                new DefaultContractResolver());
  
  builder.Services.AddControllers().AddNewtonsoftJson();
  </code></pre>
  <p><strong>Things I tried</strong></p>
  <ul>
  <li>I used <code>[FromBody],[FromForm]</code> - Both didn't work</li>
  <li>Changed <code>datatype</code> in ajax to be <code>text</code> and passed to a method with string as parameter - Did not work</li>
  <li>Tried various ways passing the <code>JSON</code>. Did not work</li>
  <li>Changed the <code>JSON</code> to <code>NewtonSoft.Json</code>. That also did not work</li>
  </ul>
  <p>Can someone tell me if there is any configuration which is missing or why this is not working</p>