Upload tips in Asp.net MVC

Source: Internet
Author: User

 

 

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 !!!

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.