title: Razor Page: RedirectToPage with Parameters
body: <p>I have a razor page which displays company and list of staff:</p>
  <pre><code>@page &quot;/admin/companies/editor/{id}&quot;
  @model EditorModel
  @{
  }
  
  &lt;h1&gt;admin . companies . editor&lt;/h1&gt;
  
  
  &lt;h4&gt;Id = @Model.Id&lt;/h4&gt;
  &lt;h4&gt;Name = @Model.OrgStructure.Organisation.Name&lt;/h4&gt;
  &lt;h4&gt;Staff Count = @Model.OrgStructure.Staff.Count&lt;/h4&gt;
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Id&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
      &lt;/tr&gt;
      @if (Model.OrgStructure.Staff.Any())
      {
          foreach (Staff s in Model.OrgStructure.Staff)
          {
              &lt;tr&gt;
                  &lt;td&gt;@s.Id&lt;/td&gt;
                  &lt;td&gt;@s.Username&lt;/td&gt;
              &lt;/tr&gt;
          }
      }
      else
      {
          &lt;tr&gt;
              &lt;td colspan=&quot;2&quot;&gt;No Staff&lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  &lt;a class=&quot;btn btn-primary&quot; asp-page=&quot;/admin/companies/staff/create&quot; asp-route-orgId=&quot;@Model.OrgStructure.Organisation.Id&quot;&gt;Create Staff&lt;/a&gt;
  
  
  @functions {
      public class EditorModel : PageModel
      {
  
          public string Id { get; set; }
  
          public OrganisationStructure OrgStructure { get; set; }
  
          public void OnGet(string id)
          {
              Id = id;
              using (DirectoryApp app = ServicesFactory.MakeDirectoryService())
              {
                  OrgStructure = app.GetOrganisationStructureAsync(new Guid(id)).Result;
              }
          }
      }
  }
  </code></pre>
  <p>When I click:</p>
  <pre><code>    &lt;a class=&quot;btn btn-primary&quot; asp-page=&quot;/admin/companies/staff/create&quot; asp-route-orgId=&quot;@Model.OrgStructure.Organisation.Id&quot;&gt;Create Staff&lt;/a&gt;
  </code></pre>
  <p>It takes me to my staff creation page:</p>
  <pre><code>@page &quot;/admin/companies/staff/create/{orgId}&quot;
  @model CreateModel
  @{
  }
  
  &lt;h1&gt;admin . companies . staff . create&lt;/h1&gt;
  
  &lt;h3&gt;OrganisationId = @Model.OrganisationId&lt;/h3&gt;
  
  &lt;form method=&quot;post&quot;&gt;
      &lt;input name=&quot;OrgId&quot; value=&quot;@Model.OrganisationId&quot; /&gt;
      &lt;div asp-validation-summary=&quot;All&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;form-group&quot;&gt;
          &lt;label&gt;User Name&lt;/label&gt;
          &lt;input name=&quot;UserName&quot; class=&quot;form-control&quot; value=&quot;@Model.UserName&quot; /&gt;
      &lt;/div&gt;
      &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;
      &lt;a class=&quot;btn btn-secondary&quot; asp-page=&quot;/admin/companies/editor&quot; asp-route-id=&quot;@Model.OrganisationId&quot;&gt;Back&lt;/a&gt;
  &lt;/form&gt;
  
  @functions {
      public class CreateModel : PageModel
      {
          [BindProperty]
          [Required]
          public string UserName { get; set; }
  
          public Guid OrganisationId { get; set; }
  
          public void OnGet(string orgId)
          {
              OrganisationId = new Guid(orgId);
          }
  
          public async Task&lt;IActionResult&gt; OnPostAsync(string userName, string orgId)
          {
              if (ModelState.IsValid)
              {
                  using (DirectoryApp app = ServicesFactory.MakeDirectoryService())
                  {
                      await app.AddStaffToOrganisationAsync(
                          new Guid(orgId),
                          new Staff()
                          {
                              Username = userName
                          });
                      return RedirectToPage(&quot;/admin/companies/editor/&quot; + orgId.ToString());
                  }
              }
              return Page();
          }
      }
  }
  </code></pre>
  <p>I have 2 questions:</p>
  <ol>
  <li><p>If I click Submit and have a Model error then I get the error message but the fields which are using @Model.OrganisationId are blanked out.  I guess that when OrganisationId is set in the OnGet() method, this is lost after a post.  Does this mean I'd need to repopulate my CreateModel.OrganisationId in the OnPostAsync() method?</p>
  </li>
  <li><p>If I am successful the line:</p>
  </li>
  </ol>
  <p>return RedirectToPage(&quot;/admin/companies/editor/&quot; + orgId.ToString());</p>
  <p>should take me back to the original screen viewing the company with the newly added staff member.  However, I am getting an error:</p>
  <p>An unhandled exception occurred while processing the request.
  InvalidOperationException: No page named '/admin/companies/editor/473be1aa-7d62-4964-b744-b34e0489d7ad' matches the supplied values.</p>
  <p>But, if I copy and paste the &quot;/admin/companies/editor/473b...&quot; into the address bar in the browser after &quot;localhost:12345&quot; then the page opens no problem.</p>
  <p>What am I doing wrong?</p>
  <h1>UPDATE</h1>
  <p>I need to replace:</p>
  <pre><code>return RedirectToPage(&quot;/admin/companies/editor/&quot; + orgId.ToString());
  </code></pre>
  <p>with</p>
  <pre><code>return RedirectToPage(&quot;/admin/companies/editor&quot;, new { id = orgId.ToString() });
  </code></pre>