title: Cannot upload images in ASP .NET MVC4
body: <p>I cannot upload image in my MVC application. Does anyone know how I can fix this error?</p>
  
  <p><strong>Model Image:</strong></p>
  
  <pre><code>namespace HelloWorld.Models
  {
      public class Image
      {
          [Required]
          [DataType(DataType.MultilineText)]
          public string ImagePath { get; set; }
  
          public int ImageId { get; set; }
      }
  }
  </code></pre>
  
  <p><strong>Index view:</strong></p>
  
  <pre><code>@model IEnumerable&lt;HelloWorld.Models.Image&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  
  @foreach (var item in Model) {
       &lt;img src="@Html.DisplayFor(modelItem =&gt; item.ImagePath)"&gt;
  }
  </code></pre>
  
  <p><strong>Create view:</strong></p>
  
  <pre><code>@model HelloWorld.Models.Image
  @{
      ViewBag.Title = "Create";
  }
  
   &lt;form method="post" action="@Url.Action("Create", "Images")"&gt;
      &lt;div&gt;
          &lt;h4&gt;Image&lt;/h4&gt;
          &lt;hr /&gt;
  
          &lt;input type="file" name="file"&gt;
          &lt;input type="submit" value="Upload"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Create action:</strong></p>
  
  <pre><code>[HttpPost]
          public ActionResult Create(Image img, HttpPostedFileBase file)
          {
              if (ModelState.IsValid)
              {
                  if (file != null)
                  {
                      file.SaveAs(HttpContext.Server.MapPath("../../Content/img/upload/") + file.FileName);
                      img.ImagePath = file.FileName;
                  }
                  db.Images.Add(img);
                  db.SaveChanges();
                  return RedirectToAction("Index");
              }
              return RedirectToAction("Create","Images");
          }
  </code></pre>
  
  <p>I think my problem is that I have model state not valid. Because I have RedirectToAction("Create","Images");</p>