0

I search so much for my problem, it seems so easy but did not get correct answer.

Here is my HTML Code

<input type="file" name="smallImage" id="smallImage" /> 
<input type="file" name="largeImage" id="largeImage" />

I can get files with Request.Files, but it does not give me the HTML file input info which the file is coming from.

As you see, I must understand which file input element sends the file.

Edit: I try this but did not work also

Request.Files["smallImage"]

1 Answer 1

3

You should use 2 arguments of type HttpPostedFileBase in your HttpPost action method with same name as of your input field(s).

[HttpPost]
public ActionResult Create(HttpPostedFileBase smallImage,
                                                     HttpPostedFileBase largeImage)
{
  // check smallImage & largeImage here
  // to do  : Return something
}

Assuming your form action value is set to this action method

@using (Html.BeginForm("Create", "YourControllerName", FormMethod.Post,
                                          new { enctype = "multipart/form-data" }))
{
   <input type="file" name="smallImage" /> 
   <input type="file" name="largeImage" /> 
   <input type="submit" />
}
Sign up to request clarification or add additional context in comments.

1 Comment

OMG I forgot to add enctype attribute to my form. You make me see this thanks a lot. After that, Request.Files["largeImage"] also worked. But your solution much better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.