Sergio Di Fiore
Sergio Di Fiore

Reputation: 466

POST receives unknown parameter name

A regular MVC controller receives a POST where the name of the parameter will have an unknow name, that is, the controller:

[HttpPost]
public ActionResult UploadFiles(HttpPostedFileBase file)
{
    // Do whatever is needed
}

Receives a HttpPostedFileBase with a Guid as name, that obviously changes at every POST not, a parameter called "file", thus being always null.

How can I receive this unknown named HttpPostedFileBase?

Upvotes: 0

Views: 73

Answers (1)

Adrian
Adrian

Reputation: 8597

Request.Files contains a collection of files uploaded by the client.

To get all the file names that were uploaded you would do:

Request.Files.AllKeys

Or you could just iterate over the collection to do something with each file.

Documentation can be found here.

Upvotes: 1

Related Questions