1

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

1
  • You are making a post request. Send your id value with Html.Hidden() helper method. Commented Jul 30, 2012 at 14:59

2 Answers 2

1

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(); } 
Sign up to request clarification or add additional context in comments.

3 Comments

He is posting a file stram. How can he access posted file with get request?
Efe, could you explain further please on Html.Hidden() for this particular situation? I do have an actionresult for getFiles where I am passing the ID
@EfeKaptan the initial GET request for the page is where he is having the issue.
0

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 } 

4 Comments

Forgot to add [HttpPost] attribute. Could you please try again?
I had that added no luck still.
Show your get method code that takes id as parameter.(First request)
I am going to be using this: blueimp.github.com/jQuery-File-Upload ... thanks for help though. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.