title: how do i refere my textbox of type file from view to controller
body: <p>Im trying to upload an image to the database but i im getting an error with object refernece not set to an instance of an object.</p>
  
  <p>i have a textbox in the view and im using memorystream in the controller but i cant store the image to the memorystream.</p>
  
  <p>i also have a model where have this property </p>
  
  <pre><code>public HttpPostedFileBase file { get; set; }
  </code></pre>
  
  <p>heres the code from the view:</p>
  
  <pre><code>@using (Html.BeginForm()) {
  @Html.ValidationSummary(true)
  
  &lt;fieldset&gt;
      &lt;legend&gt;Picture&lt;/legend&gt;
  
           @Html.TextBoxFor(m =&gt; m.file, new { type = "file" })
          @*&lt;input type="file" value="file" /&gt;*@
          &lt;input type="submit" value="Create" /&gt;
  &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>and this is the code from the controller:</p>
  
  <pre><code>[HttpPost]
      public ActionResult Create(HttpPostedFileBase file)
      {
  
          var memoryStream = new System.IO.MemoryStream();
          file.InputStream.CopyTo(memoryStream);
  
          var fileBytes = memoryStream.ToArray();
  
          return RedirectToAction("Index");
      }
  </code></pre>