Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

HttpPostedFileBase is always null in MVC3 for File Upload

$
0
0

Hi All,

I am getting HttpPostedFileBase null always. I have tried most of the solutions found in the net. But did not work. Could you please help me? Below is my code.

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

 public ActionResult FileUpload(HttpPostedFileBase uploadFile)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    if (uploadFile.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(uploadFile.FileName);
                        var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                        uploadFile.SaveAs(path);
                    }

}

Thanks,

Lijo


Viewing all articles
Browse latest Browse all 3527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>