title: dotnet core get dictionairy from form data
body: <p>How do I get a <code>Dictionairy&lt;string, string&gt;</code> from <code>form-data</code>?</p>
  <p>View model:</p>
  <pre class="lang-cs prettyprint-override"><code>public class SubmitRequestModel
  {
    public Dictionairy&lt;string, string&gt; InputFields { get; set; }
   
    public List&lt;IFormFile&gt; Attachments { get; set; }
  }
  </code></pre>
  <p>Action:</p>
  <pre class="lang-cs prettyprint-override"><code>[HttpPut(&quot;{id:int}&quot;)]
  public async Task&lt;IActionResult&gt; Submit(int id, [FromForm] SubmitRequestModel model)
  {
    // model.InputFields is initialized but it's count is 0
    // do whatever
  }
  </code></pre>
  <p>This is an API controller. Not cshtml or razor related.</p>
  <p>So the <code>model.InputFields</code> is not <code>null</code> but it's count is <code>0</code>. When I look at the raw request. I can see that the input is received, but it is not bound to the dictionairy in the model.</p>
  <p>The values of the <code>Request.Form</code> collection: <a href="https://prnt.sc/11x532p" rel="nofollow noreferrer">https://prnt.sc/11x532p</a></p>
  <p>I need to use form data because we are uploading files with the request. This requires <code>multipart/form-data</code>.</p>
  <p>How do I successfully parse the data to the model?</p>
  <hr />
  <p>Info on how I tested this:</p>
  <p>I have swagger set-up. I import the generated Swagger OpenAPI json in to Postman and test this way. I believe that this should be the correct request, that Swagger generated. But I'm not sure if it formatted the dictionairy the right way. It would be the right way for a JSON data request. But I'm not sure if that applicates here.</p>