MVC 学习第十一节 文件的上传

文件的上传

下面来说一下与本篇本无关的话题就是文件的上传,我这里也不多做解释了,直接上代码。

View:

   1 <form action="@Url.Action("Process") " enctype="multipart/form-data" method="post">
   2 <input name="up1" type="file" /> <input type="submit" />
   3 </form>

Action(Process):

        public ActionResult shangchuan()
        {
            return View();
        }
    [HttpPost]
    public ActionResult shangchuan(HttpPostedFileBase up1)
    {//参数名与name名一致即可
        up1.SaveAs(Server.MapPath("~/" + up1.FileName));
       return Content(up1.FileName);
    }

显示:

提交后:

再看看文件夹,文件已经上传成功:

好了,基础基本上就这些了,过年后我将用MVC3写一个小型的CMS

原文地址:https://www.cnblogs.com/ayzhanglei/p/2880872.html