title: How do I post an IFormFile in ASP.Net Core 2.0 Razor Pages?
body: <p>I'm working in an application with ASP.Net Core 2.0 and Razor Pages. I have been following the Microsoft Docs on how to upload files to Azure blob storage but I can't get it to work so far.</p>
  
  <p>I have two separate model classes. One for the file upload and one for the Word.</p>
  
  <p>File upload class:</p>
  
  <pre><code>public class WordUpload
  {
      public IFormFile SoundFile { get; set; }
      public IFormFile SoundFileSentence { get; set; }
  }
  </code></pre>
  
  <p>Other class:</p>
  
  <pre><code>public class Word
  {
      public int ID { get; set; }
      public string Answer { get; set; }
      public string AlternativeAnswer { get; set; }
      public string Hint { get; set; }
      public int Length { get; set; }
      public int Vowels { get; set; }
      public string Language { get; set; }
      public string Category { get; set; }
      public int Module { get; set; }
      public string Difficulty { get; set; }
      public string Sound { get; set; }
      public string SoundSentence { get; set; }
  }
  </code></pre>
  
  <p>Page with WordUpload.SoundFile that is not passed. This is the problem as it always returns null.</p>
  
  <pre><code>public class CreateModel : PageModel
  {
      private readonly Data.ApplicationDbContext _context;
      private readonly IWordRepository _wordRepository;
  
      public CreateModel(Data.ApplicationDbContext context, IWordRepository wordRepository)
      {
          _context = context;
          _wordRepository = wordRepository;
      }
  
      /// &lt;summary&gt;
      /// OnGet triggers when the page is opened
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public IActionResult OnGet()
      {
          Word = new Word
          {
              Answer = "",
              AlternativeAnswer = "",
              Hint = "Hint",
              Length = 0,
              Vowels = 0,
              Language = "DK",
              Category = "",
              Module = 0,
              Difficulty = "",
              Sound = "",
              SoundSentence = ""
          };
  
          return Page();
      }
  
      [BindProperty]
      public WordUpload WordUpload { get; set; }
  
      [BindProperty]
      public Word Word { get; set; }
  
      /// &lt;summary&gt;
      /// Posts the data to the database async
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          if (!ModelState.IsValid)
          {
              return Page();
          }
  
          // Get the number of vowels in the word
          Word.Vowels = _wordRepository.NumberOfVowels(Word.Answer);
  
          // Save the length
          Word.Length = Word.Answer.Length;
  
          // upload file to blob storage
          Word.Sound = _wordRepository.UploadAudio(WordUpload.SoundFile);
  
          // save to db
          _context.Word.Add(Word);
          await _context.SaveChangesAsync();
          return RedirectToPage("./Index");
      }
  }
  </code></pre>
  
  <p>And the view - page:</p>
  
  <pre><code>@page
  @model Fabetio.Web.Pages.Words.CreateModel
  
  @{
      ViewData["Title"] = "Create";
  }
  
  &lt;div class="container-fluid darkblue-background"&gt;
  
      &lt;br&gt;
      &lt;br&gt;
  
      &lt;div class="row"&gt;
          &lt;div class="col-md-6 col-md-offset-3"&gt;
              &lt;div class="task--card"&gt;
  
                  &lt;div class="dasboard--title"&gt;
                      &lt;h1&gt;@ViewData["Title"]&lt;/h1&gt;
                      &lt;p class="subtitle"&gt;Subtitle.&lt;/p&gt;
                  &lt;/div&gt;
  
                  &lt;form method="post"&gt;
                      &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
                      &lt;input type="hidden" asp-for="Word.ID" /&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.Answer" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.Answer" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.Answer" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.AlternativeAnswer" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.AlternativeAnswer" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.AlternativeAnswer" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.Hint" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.Hint" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.Hint" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.Language" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.Language" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.Language" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.Category" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.Category" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.Category" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.Module" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.Module" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.Module" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="Word.Difficulty" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="Word.Difficulty" class="form-control" /&gt;
                          &lt;span asp-validation-for="Word.Difficulty" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label asp-for="WordUpload.SoundFile" class="control-label"&gt;&lt;/label&gt;
                          &lt;input asp-for="WordUpload.SoundFile" type="file" class="form-control" /&gt;
                          &lt;span asp-validation-for="WordUpload.SoundFile" class="text-danger"&gt;&lt;/span&gt;
                      &lt;/div&gt;
  
                      &lt;br&gt;
                      &lt;br&gt;
  
                      &lt;div class="form-group"&gt;
                          &lt;input type="submit" value="Create" class="btn btn--blue" /&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;br&gt;
      &lt;br&gt;
  &lt;/div&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  }
  </code></pre>
  
  <p>The WordUpload.SoundFile is not passed with the model. When I debug the application, it is returned as null in the controller/page. All the other properties are passed without any issue.</p>
  
  <p>Do you know how to pass the file?</p>