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.