1

I am developing an app in asp.net mvc in which I want to upload a file. On the view side I render my upload file field at run time when my view calls the controller, It gives all the data in FormCollection and on the controller side I am able to get only name of the uploading file in the form of string and Request.File[0].count is equals to zero. Now how I can solve this problem.

Code can be share on demand.

Regards

Mr. B
  • 33
  • 3
  • 5
  • Refer http://stackoverflow.com/questions/9411563/asp-net-mvc3-razor-file-upload-gives-zero-as-file-count for a related problem – LCJ Dec 20 '12 at 14:45

1 Answers1

3

Try adding this in your View:

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
   <input type="file" id="file" name="file" />
   <input type="submit" value="upload" />
}

And in your controller file:

[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
    return View();
}
ionden
  • 12,536
  • 1
  • 45
  • 37