title: Multiple Attributes Html.BeginForm MVC id and enctype as part of file upload
body: <p>As part of file upload (ASP.NET MVC3) adding id and enctype attributes to HTML.BeginForm return HttpPostedFileBase as null</p>
  
  <p>Model:</p>
  
  <pre><code>public class ProfileModel
  {
   [UIHint("Upload")]
   public HttpPostedFileBase ImageUpload { get; set; }
  }`
  </code></pre>
  
  <p>ProfileForm.cshtml</p>
  
  <pre><code>@using (Html.BeginForm("Update", "Profile", new { ProfileId = ViewBag.ProfileID }, FormMethod.Post, new { @enctype = "multipart/form-data", @id = "ProfileForm" }))
  {
  
      &lt;div&gt;
          @Html.LabelFor(model =&gt; Model.ImageUpload)
          @Html.TextBoxFor(model =&gt; Model.ImageUpload, new { type = "file" })
      &lt;/div&gt;
      &lt;div class='buttons'&gt;
          &lt;input type="submit"  value='Save' /&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>public Upload(ProfileModel viewModel)
  {
    if (viewModel.ImageUpload != null &amp;&amp; viewModel.ImageUpload.ContentLength &gt; 0)
   {
     var uploadDir = "~/uploads";
     var imagePath = Path.Combine(Server.MapPath(uploadDir), viewModel.ImageUpload.FileName);
     var imageUrl = Path.Combine(uploadDir, viewModel.ImageUpload.FileName);
     viewModel.ImageUpload.SaveAs(imagePath);
     }
  }
  </code></pre>
  
  <hr>
  
  <p>if I remove the <code>@id = "ProfileForm"</code> attribute as below I am getting the HttpPostedFileBase (ImageUpload) value.</p>
  
  <pre><code>@using (Html.BeginForm("Update", "Profile", new { ProfileId = ViewBag.ProfileID }, FormMethod.Post, new { @enctype = "multipart/form-data"}))
  {  }
  </code></pre>
  
  <p>I need to pass both id and enctype - can anyone please suggest me what I am doing wrong or is there any better way to do ?</p>