title: How to keep my model data when do GET>POST>REDIRECT to upload a file?
body: <p>I want to create a register form using MVC which include a <strong>profile photo</strong>. I <em>don't want to add record</em> for people <em>before</em> completing the form (including profile photo upload). Also I want my UploadImage view and controller to be <strong>re-usable</strong> for many forms (not just this form). I pass three variables to my upload form through <code>ActionLink</code>: <code>RedirectAction (RA)</code>, <code>RedirectController (RC)</code>, and <code>dataname</code> and the procedure goes like this:</p>
  
  <ol>
  <li><p>I store <code>RA, RC, dataname</code> in <code>ViewBag</code>, then  put them in <code>hidden &lt;input&gt; tags</code> to be submitted when POSTing the file</p>
  
  <pre><code>// GET: UploadImage/Upload
    public ActionResult Upload(string RA, string RC, string dataname)
      {
          ViewBag.RedirectAction = RA;
          ViewBag.RedirectController = RC;
          ViewBag.DataName = dataname;
  
          return View();
      }
  </code></pre></li>
  <li><p>Put these lines in my Upload.cshtml (View):</p>
  
  <pre><code>@using (Html.BeginForm("Upload", "UploadImage", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
      &lt;input type="file" name="file" /&gt;
      &lt;input type="hidden" name="RA" value="@ViewBag.RedirectAction" /&gt;
      &lt;input type="hidden" name="RC" value="@ViewBag.RedirectController" /&gt;
      &lt;input type="hidden" name="dataname" value="@ViewBag.DataName" /&gt;
      &lt;input type="submit" name="Submit" id="Submit" value="Upload" /&gt;
  } 
  </code></pre></li>
  <li><p>Store the <code>filename</code> in <code>TempData</code> with <code>dataname</code> as the <code>Key</code> and redirect to <code>/RC/RA</code>:</p>
  
  <pre><code>  // POST: UploadImage/Upload/
    [HttpPost]
     public ActionResult Upload(HttpPostedFileBase file, string RA , string RC , string dataname)
      {
           var filepath = "C:/myfilename.jpg";
           TempData.Add(dataname, filepath);
         return RedirectToAction(RA,RC);
      }
  </code></pre></li>
  <li><p>And get my filepath by utilizing <code>TempData</code> in my register form:</p>
  
  <pre><code> @if (TempData.Keys.Contains("MyData")) { 
  &lt;div class="form-group"&gt;
      &lt;p&gt;@TempData["MyData"].ToString()&lt;/p&gt;
  &lt;/div&gt;} 
  </code></pre></li>
  </ol>
  
  <p>The code works just fine, but <strong>the essential caveat is that I don't want other completed fields to get lost</strong> when redirected to the register form. How can I solve this problem ?</p>