title: How to upload video in ASP.NET MVC 5 and pass the video file from a view to a method?
body: <p>I'm writing an MVC 5 web application to update blog posts. I want to be able to have the user upload a video to the content folder and then store the filename as a string in the database. However, I seem to be missing one essential piece though. </p>
  
  <p>I have a method to update the posts which is working except for the video part.</p>
  
  <pre><code>public ActionResult Update(int? id, string title, string body, DateTime dateTime, string tags, Video video)
  {
      if (!IsAdmin)
      {
          return RedirectToAction("Index");
      }
  
      var post = GetPost(id); // get the post object
  
      post.Title = title;
      post.Body = body;
      post.DateTime = dateTime;
      post.Tags.Clear();
      post.VideoFileName = UploadVideo(video);
  </code></pre>
  
  <p>I have created a class for the Video with one property.</p>
  
  <pre><code>public class Video
  {
      public HttpPostedFileBase File { get; set; }
  }
  </code></pre>
  
  <p>Then a method in the same class as the <code>Update</code> method to upload the video and return the filename.</p>
  
  <pre><code>[HttpPost]
  public string UploadVideo(Video video)
  {
      if (video.File.ContentLength &lt;= 0) return null;
      var fileName = Path.GetFileName(video.File.FileName);
      if (fileName == null) return null;
      var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
      video.File.SaveAs(path);
  
      return fileName;
  }
  </code></pre>
  
  <p>Then I have a View for the Update method but I don't know how to get the video object from this View into the Update method so that I can pass it to the <code>UploadVideo</code> method.</p>
  
  <pre><code>&lt;form action="@Href("~/Posts/Update")" method="post" id="postForm"&gt;
  @if(Model.Id != -1)
  {
      &lt;input type="hidden" name="id" value="@Model.Id"/&gt;
  }
      @{ var dateTime = Model.DateTime.Year &gt; 2000 ? Model.DateTime : DateTime.Now; }
      &lt;input type="text" name="dateTime" value="@dateTime "/&gt; Date&lt;br /&gt;
      &lt;input type="text" name="title" value="@Model.Title " /&gt; Title&lt;br /&gt;
      &lt;input type="text" name="tags" value="@ViewBag.Tags " /&gt; Tags&lt;br /&gt;
      &lt;textarea name="body" rows="10" cols="80"&gt;@Model.Body&lt;/textarea&gt;&lt;br /&gt;
      &lt;br/&gt;
      &lt;br/&gt;
      &lt;input type="file" name="video" /&gt;
      &lt;br/&gt;
      &lt;br/&gt;
      &lt;input type="submit" name="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Using <code>&lt;input type="file" name="video" /&gt;</code> results in the video object being null when passed into the Update method. </p>
  
  <p>How would you pass in the video file to the Update method with all the other text data set in the View such as <code>dateTime</code>,<code>title</code>,<code>tags</code> and <code>body</code>?</p>