asp.NetMVCは簡単なアップロード機能を実現

1042 ワード

方法1:
Home/Index.aspxのコード
 
  





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");
}

方法2:
Home/Index.aspxのコード
 
  
" enctype="multipart/form-data" method="post">



Homecontrollerのコード
 
  
public ActionResult upload2(HttpPostedFileBase up1)
{
up1.SaveAs("d:\\8.jpg");
return Content(up1.FileName);
}