I am trying to upload a file to location ~/Files however I am not successful.
I use MVC 3 and my code is thus.
I have a controller GetFileController
I have an action method in this controller
I am trying to upload a file to location ~/Files however I am not successful.
I use MVC 3 and my code is thus.
I have a controller GetFileController
I have an action method in this controller
I have an action method in this controller
If this is the only action method in your controller then you'll receive this error. Add a GET Action Method:
[HttpGet] public ActionResult GetFiles() { return View(); } GET request for the page is where he is having the issue.Post your id field with a hidden input, as :
@using (Html.BeginForm("GetFiles", "GetFile", FormMethod.Post, new { enctype = "multipart/form-data" })) { <input name ="id" type="hidden" value="1"/> <label for="file">Upload Image:</label> <input type="file" name="file" id="file"/> <input type="submit" value="Upload Image" /> } [HttpPost] public ActionResult GetFiles(int id, HttpPostedFileBase file) { // file stream logic }