Method One:
Code in the Home/index.aspx
Copy Code code 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 the 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 Two:
Code in the Home/index.aspx
Copy Code code as follows:
<form action= "<%=url.action (" upload2 ")%>" enctype= "Multipart/form-data" method= "Post >
<input name= "up1" type= "file"/><input type= "Submit"/>
</form>
Code in the HomeController
Copy Code code as follows:
Public ActionResult upload2 (HttpPostedFileBase up1)
{
Up1. SaveAs ("d:\\8.jpg");
Return Content (up1. FileName);
}