Reputation: 49
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
Upvotes: 1
Views: 99
Reputation: 465
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
}
Upvotes: 0
Reputation: 35399
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();
}
Upvotes: 1