title: Post-Redirect-Get pattern in long / wizard style forms
body: <p>I have a project with a form that is completed over several parts. E.g. Part 1 might include your name, and part 2 your address.</p>
  
  <p>In MVC I have several views which represent each of the parts and one model to hold all the form data.</p>
  
  <p>I would like to save the form data at the completion of each part, and retrieve the saved record on the next part (so that the whole model is available at each stage).</p>
  
  <p>I am using Post-Redirect-Get to avoid the 'form may be resubmitted' warnings from browsers using the back and forward buttons.</p>
  
  <p><strong>Controller code</strong></p>
  
  <pre><code>[HttpGet]
  [Route("Form/Part/{id}")]
  public ActionResult Part(int id, int? recordId) 
  {
      var model = new MyVM();
      if(recordId.HasValue) {
          // get record from DB
          // map record to 'model'
      }
      return View("Form.{id}", model);
  }
  
  [HttpPost]
  [Route("Form/Part/{id}")]
  public ActionResult Part(int id, MyVM model) 
  {
      // map model to entity
      // save/update entity
      return RedirectToAction($"Form/Part/{id + 1}", new { recordId = recordId })
  } 
  </code></pre>
  
  <p>My question is how best to retain the ID of the newly created / updated record and pass it to the next form part.</p>
  
  <p>Whilst passing the <code>recordId</code> as a <code>routeValue</code> <em>works</em>, it breaks when I use the browser back button as the <code>recordId</code> in the querystring is lost.</p>
  
  <p>I have considering storing this in the session perhaps, but don't really want to bring the <code>HttpContext</code> into play if I don't have to for testing reasons.</p>
  
  <p>Is there a recommended way to achieve this kind of thing? Any thoughts on the various ways to keep track of the current record would be greatly appreciated.</p>