ASP. net mvc uploads files using the input tag, mvcinput
Some time to learn about ASP. net mvc. Document uploading is a feature that must be supported during development. Previously, the upload was implemented using the third-party control uploadify. Today, the VS standard label input type = "file" is used.
In the controller, create two ActionResult (), the first is the View, and the second is the Action, that is, processing the upload. The difference between the two is that a return View (), A return Content ("").
The uploaded files will be stored in the Temp directory. In the above code example, there is a black arrow of the dotted line, which is the name of the Input type = "file.
Real-time Demonstration:
Aspnet mvc20 uploading multiple files
For (fileCount = 0; fileCount <files. Count; fileCount ++)
{
// Define the object for accessing the client to upload files
System. Web. HttpPostedFile postedFile = files [fileCount];
String FileType = postedFile. ContentType. ToString (); // obtain the file type to be uploaded and verify the file header.
String fileName, fileExtension;
// Get the uploaded file name
FileName = System. IO. Path. GetFileName (postedFile. FileName );
// Get the file extension
FileExtension = System. IO. Path. GetExtension (fileName );
// When the file to be uploaded is not empty, verify that the file name and size are consistent. If not, upload is not allowed.
If (FileType = "text/plain" & fileExtension. toLower () = ". txt ") | (FileType =" application/x-zip-compressed "& fileExtension. toLower () = ". zip ") | (FileType =" application/octet-stream "& fileExtension. toLower () = ". rar ") & postedFile. contentLength/1024 <= 1024)
{// Check whether the file header matches the file name to limit the File Upload type. Note: The File Upload types include TXT, ZIP, and RAR, and the file size can only be 1 MB.
If (fileName! = String. Empty)
{
FileName = RandomFileName () + fileExtension;
// Upload File Information
StrMsg. Append ("type of the uploaded file:" + postedFile. ContentType. ToString () + "<br> ");
StrMsg. Append ("client file address:" + postedFile ...... remaining full text>
How does aspnet mvc30 upload images?
<Input type = "file" id = "filePicture" name = "fileData"/>
The parameter HttpPostedFileBase fileData is received in control and is being processed.