Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is my code:

View.cshtml code:---

C#
@using (Html.BeginForm("UploadVideos", "Videos", FormMethod.Post, new { enctype = "multipart/form-data", @data_ajax = "false" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
        <input type="file" value="file" id="fileCntrl" name="uploadFile" accept="video/*" data-val="true" data-val-required="File is required"  />
        <input type="submit" value="Upload" />
  }


Controller code:-----

C#
public ActionResult UploadVideos()
       {
           return View();
       }

       [HttpPost]
       public ActionResult UploadVideos(HttpPostedFileBase fileCntrl)
       {

           if (fileCntrl != null && fileCntrl.ContentLength > 0)
               {
                   var filename = Path.GetFileName(fileCntrl.FileName);
                   var path = Path.Combine(Server.MapPath("~/Images"), filename);
                   fileCntrl.SaveAs(path);
               }

           return View();
       }
Posted
Updated 8-Oct-14 2:11am
v4
Comments
Richard Deeming 22-Aug-14 9:08am    
Shouldn't your action's parameter name match the name attribute on your file input? ("uploadFile" instead of "fileCntrl")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900