I have checked various answer for this, but none of them works for me, my code in .cshtml is as follows:
You have to add enctype = "multipart/form-data"
in form tag.
@using (Html.BeginForm("Action", "Controller", FormMethod.Post,
new { enctype = "multipart/form-data" }))
Try this c# code in controller action
if (Request.Files != null && Request.Files.Count > 0)
{
HttpPostedFileBase file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
}
}
You have to retrieve the file.
if you want to use MVC to upload file you need: - create form and have to set tag: enctype = "multipart/form-data" - create input with name same HttpPostedFileBase in controller
try this one:
var fileCount = Request.Files.Count;
if (fileCount > 0)
{
for (int i = 0; i < (fileCount); i++)
{
HttpPostedFileBase Yourfile= Request.Files[i] as HttpPostedFileBase;
// do whatever with your file
}
}