In the past two days, the Asp.net MVC project allows users to upload an image as their Avatar.
HtmlCode
<Form method = "Post" enctype = "multipart/form-Data" Action = "/home/uploadfile">
<Input type = "file" id = "uploadfile"/>
<Input type = "Submit" value = "save"/>
</Form>
Controller code
[Httppost]
Public Actionresult Uploadfile(Httppostedfilebase File)
{
Return View();
}
Which file is always null.
On an English website, you can see:
The file upload control must have a name value, and the file in the httppostedfilebase file on the controller must be the name value of the upload control.
Add the following code:
<Form method = "Post" enctype = "multipart/form-Data" Action = "/home/uploadfile">
<Input type = "file" id = "uploadfile" name = "file"/>
<Input type = "Submit" value = "save"/>
</Form>
The Controller code will not be written. It is the same as above.
After tracking, file is no longer null.
Write this article for memo !!!