ASP. net mvc uploads files using the input tag, mvcinput

Source: Internet
Author: User

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.


If you do not want the Razor statement but use the traditional form method, refer:

Real-time Demonstration:


 


In aspnet mvc3, the parameter HttpPostedFileBase file in the controller is used to obtain the uploaded file and the file path is incorrect.

I tested Google browser instead of IE. In IE, file. FileName contains the path name, but Google does not. Therefore, in my previous answers, I will say that the file name does not contain the path name. I think this is the cause of your problem. You can add a judgment before saving:
String fileName = file. FileName;
If (fileName. LastIndexOf ("\")>-1)
{
FileName = fileName. Substring (fileName. LastIndexOf ("\") + 1 );
}
This makes it okay, and is compatible with Google and IE.

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.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.