title: ASP.NET MVC2 +file uploading (HttpPostedFileBase class)
body: <p>I have problem with uploading my file. I want to upload it from my <strong>edit view:</strong></p>
  
  <pre><code>    &lt;% 
      using (Html.BeginForm("edit","profile",FormMethod.Post, new { enctype="multipart/form-data" }))
      {%&gt;
      &lt;%: Html.ValidationSummary(true) %&gt;
  
      &lt;%: ViewData["ErrorMessage"] %&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;Fields&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.Image) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;input type="file" id="Image" name="Image" /&gt;
              &lt;label id="LabelErrorImage" class="errorMessage" /&gt;
          &lt;/div&gt; 
  
          &lt;p&gt;
              &lt;input type="submit" value="Save" onclick="return Validate(); return false;"/&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  
  &lt;% } %&gt;
  </code></pre>
  
  <p>I want to use <strong>HttpPostedFileBase</strong> class. My edit action:</p>
  
  <pre><code>[Authorize]
          [HttpPost]
          [AcceptVerbs(HttpVerbs.Post)]
          public ActionResult Edit(string id, HttpPostedFileBase file, FormCollection formValues)
          {
                      if (ModelState.IsValid)
                      {
  
                          if (file != null &amp;&amp; file.ContentLength &gt; 0)
                          {
                              CustomHelpers.createFolder();
                              var tmpPath = MyConfig.UPLOAD_FILE_PATH + "/" + Membership.GetUser().ProviderUserKey.ToString();
                              var path = Path.Combine(Server.MapPath(MyConfig.UPLOAD_FILE_PATH), "Avatar");
                              var fileExtension = Path.GetExtension(file.FileName);
                              file.SaveAs(path);
                              user.Image = "Avatar";
                          }
                          adventureDB.SaveChanges();
  
                          return RedirectToAction("Index");
                      }
          }
  </code></pre>
  
  <p>But I always have empty the file object, why????? Do you have any ideas, suggestions why it can work like that? Maybe there is problem how I pass on the file value to my Edit action?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
   IT IS REALLY STRANGE AS EVEN WHEN I REMOVE<br>
    <code>using (Html.BeginForm("Index","Profile",FormMethod.Get, new { enctype="multipart/form-data" }))</code></p>
  
  <p>The page source still has: </p>
  
  <pre><code>&lt;body&gt;
  
      &lt;form method="post" action="6111e591-b92d-4bcb-b214-ab8f664b35f9" id="form1"&gt;
  </code></pre>
  
  <p>I mean I can not change the  tag but have no idea why :/</p>