title: Cannot POST Data in .NET Core MVC
body: <p>I am trying to make a POST request using .NET CORE MVC by submitting a form. The call is successfully made from the view and looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/tmC8s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tmC8s.png" alt="enter image description here"></a></p>
  
  <p>My controller code looks like this:</p>
  
  <pre><code>[HttpPost("fred-responses-report-result/{formId:int?}")]
  public async Task&lt;IActionResult&gt; FredResponsesReportResult(int? formId, ReportFilters filters)
  </code></pre>
  
  <p>The <em>formId</em> param is passed through fine and set to 63, but the report filters object (below) is just <code>null</code>. The class is below, if it matters:</p>
  
  <pre><code>public class ReportFilters
  {
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
      public DateTime FromDate { get; set; }
  
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
      public DateTime ToDate { get; set; }
  }
  </code></pre>
  
  <p>So far I have read <a href="https://andrewlock.net/model-binding-json-posts-in-asp-net-core/" rel="nofollow noreferrer">this article</a> and <a href="https://stackoverflow.com/questions/11492325/post-json-fails-with-415-unsupported-media-type-spring-3-mvc">this post</a>. I have tried removing the attributes from the model - didn't help. I tried pre-pending <code>[FromBody]</code> and <code>[FromForm]</code> to the controller param, and it resulted in a 415 http error. </p>
  
  <p>I am at a bit of a loss at how to get this to work at this point. If I look at the "view source" (in the screenshot) it seems like these are just being passed as HTML-encoded strings, rather than JSON, though I don't understand why. Regardless, what is the proper approach here?</p>
  
  <p><strong>EDIT</strong>, here is the code making the call:</p>
  
  <pre><code>            &lt;form action="" method="post"&gt;
              &lt;div class="row gray-background"&gt;
                  &lt;!--Date Filter--&gt;
                  &lt;div class="col-12"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-2 offset-1 bold-font"&gt;
                              &lt;p&gt;Submitted Date&lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div class="col-3"&gt;
  
                              &lt;div class="date datepicker fromDate"&gt;
                                  &lt;label for="fromDate"&gt;From&lt;/label&gt;
                                  &lt;div class="input-group"&gt;
                                      &lt;input id="fromDate" name="fromDate" type="text" class="form-control" value="1"&gt;
                                      &lt;span class="input-group-addon"&gt;
                                          &lt;i class="fa fa-calendar fa-lg"&gt;&lt;/i&gt;
                                      &lt;/span&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                          &lt;/div&gt;
                          &lt;div class="col-3"&gt;
                              &lt;div class="date datepicker toDate"&gt;
                                  &lt;label for="toDate"&gt;To&lt;/label&gt;
                                  &lt;div class="input-group"&gt;
                                      &lt;input id="toDate" name="toDate" type="text" class="form-control" value="@Model.ReportFilters.ToDate"&gt;
                                      &lt;span class="input-group-addon"&gt;
                                          &lt;i class="fa fa-calendar fa-lg"&gt;&lt;/i&gt;
                                      &lt;/span&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;!--Update Filters Button--&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-12 d-flex justify-content-center"&gt;
                              &lt;button class="btn button-margin btn-primary"
                                      type="submit"&gt;
                                  Update Filter
                              &lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>