title: MVC razor file upload
body: <p>Literally brand new to the MVC idea, but I'm trying to get a file to upload from the view and pass it to the controller which then uploads to azure blob storage. However I cannot manage to get the file that the user selects to actually pass to the controller. I've seen <a href="https://stackoverflow.com/questions/15680629/mvc-4-razor-file-upload">MVC 4 Razor File Upload</a> and tried the answer but it's not working out. </p>
  
  <p>my View where the file is selected</p>
  
  <pre><code>  @using (Html.BeginForm("FileView", "Shares", FormMethod.Post, new { enctype = "multipart/form-data" })) 
  
   {
    @Html.AntiForgeryToken()
  
  &lt;div class="form-horizontal"&gt;
      &lt;h4&gt;FileUploadModel&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.numshares, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.numshares, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.numshares, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.minshares, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.minshares, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.minshares, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.file, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
  
               &lt;input type="file" name="file" id="file" /&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>  [HttpPost]
      public ActionResult FileView(FileUploadModel model, HttpPostedFileBase file)
      {
          // Retrieve storage account from connection string.
          CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            ConfigurationManager.AppSettings["StorageConnectionString"]);
          // Create the blob client.
          CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
  
          // Retrieve reference to a previously created container.
          CloudBlobContainer container = blobClient.GetContainerReference("shares");
  
          // Retrieve reference to a blob named "myblob".
          CloudBlockBlob blockBlob;
  
          // Create or overwrite the "myblob" blob with contents from a local file.
  
          BinaryReader b = new BinaryReader(file.InputStream);
          byte[] binData = b.ReadBytes(model.file.ContentLength);
          int numshares = model.numshares;
          int minshares = model.minshares;
          Share[] share = shares(binData, numshares, minshares);
  
          foreach (Share s in share)
          {
              String n = model.file.FileName + s.getId().ToString();
  
              blockBlob = container.GetBlockBlobReference(n);
              blockBlob.UploadFromByteArray(s.serialize(), 0, s.serialize().Length);
  
          }
  
  
              return View();
  
      }
      public ActionResult FileView()
      {
          return View();
      }
  </code></pre>
  
  <p>Got absolutely no idea what's wrong with it so any help would be appreciated thank you!</p>