Method 1:
In home/index. aspx
Code Copy code The Code is as follows: <% using (html. beginform ("up", "home", formmethod. Post, new {enctype = "multipart/form-Data"}) {%>
<Input type = "file" name = "upfile"/>
<Input type = "Submit" name = "Upload" value = "Upload"/>
<% }%>
Code in homecontroller
[Code]
[Acceptverbs (httpverbs. Post)]
Public actionresult up (httppostedfilebase upfile)
{
If (upfile! = NULL)
{
If (upfile. contentlength> 0)
{
Upfile. saveas ("D: \ 7.jpg ");
}
}
Return redirecttoaction ("Index ");
}
Method 2:
Code in home/index. aspxCopy codeThe Code is as follows: <form action = "<% = URL. Action (" upload2 ") %>" enctype = "multipart/form-Data" method = "Post">
<Input name = "up1" type = "file"/> <input type = "Submit"/>
</Form>
Code in homecontrollerCopy codeThe Code is as follows: public actionresult upload2 (httppostedfilebase up1)
{
Up1.saveas ("D: \ 8.jpg ");
Return content (up1.filename );
}