Method 1:
Code in Home/Index. aspx
Copy codeThe 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. aspx
Copy 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 Homecontroller
Copy codeThe Code is as follows:
Public ActionResult upload2 (HttpPostedFileBase up1)
{
Up1.SaveAs ("d: \ 8.jpg ");
Return Content (up1.FileName );
}