title: ASP Core Razor Pages Change BindProperty Value on Post
body: <p>I'm creating a form using one razor page (I know this may not be a good idea, but I'm trying to do some [not so] rapid prototyping.  Basically, the first step is that the user enters a bunch of data, and the next step is that the user will upload some files.  My page model looks like this:</p>
  
  <pre><code>public class CreateModel : PageModel
  {
      private readonly DefaultDbContext _context;
  
      public CreateModel(DefaultDbContext context)
      {
          _context = context;
      }
  
      public async Task&lt;IActionResult&gt; OnGet(Guid id)
      {
          FileUpload = false;
          return Page();
      }
  
      [BindProperty]
      public bool FileUpload { get; set; } // Stored in a hidden field in my cshtml
  
  
      // To protect from overposting attacks, please enable the specific properties you want to bind to, for
      // more details see https://aka.ms/RazorPagesCRUD.
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          FileUpload = true; // Hidden field is always false  
          return Page();
      }
  }
  </code></pre>
  
  <p>This is what my form looks like:</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data"&gt;
      &lt;input type="hidden" asp-for="FileUpload" /&gt;
  
      @if (!Model.FileUpload)
      {
          // Do some stuff
      }
      else
      {
          &lt;div class="form-group"&gt;
              &lt;label asp-for="Upload" class="control-label"&gt;&lt;/label&gt;
              &lt;input type="file" asp-for="Upload" multiple /&gt;
              &lt;span asp-validation-for="Upload" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      }
      &lt;div class="form-group"&gt;
          @if (Model.FileUpload)
          {
              &lt;input type="submit" value="Finished" class="btn btn-primary" /&gt;
          }
          else
          {
              &lt;input type="submit" value="Next" class="btn btn-primary" /&gt;
          }
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>When I click submit the first time, I would expect <code>FileUpload</code> to be <code>true</code>, which it is when I step through the <code>.cshtml</code> page in the debugger.  The problem is that when the page is sent back to the browser, the value is always false:</p>
  
  <pre><code>        &lt;input type="hidden" data-val="true" data-val-required="The FileUpload field is required." id="FileUpload" name="FileUpload" value="False" /&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>