码迷,mamicode.com
首页 > Web开发 > 详细

asp.net mvc上传文件

时间:2015-06-20 14:19:05      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

在view视图里面

@using (Html.BeginForm("uploadfile", "home", FormMethod.Post, new { enctype = "multipart/form-data"}))
{
<input type="file" name="file"/>
<input type="submit" value="submit"/>
}

在controller

[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file)
{
if (file==null )
{
return Content("上传的文件为空","text/plain");
}
 string  fileName = Request.MapPath("~/image/")+DateTime.Now.ToFileTime().ToString ()+".jpg";
try
{
file.SaveAs(fileName);
}
catch
{

return Content("上传出错","text/plain");
}
return Content("上传成功", "text/plain");
}

asp.net mvc上传文件

标签:

原文地址:http://www.cnblogs.com/viphuangshaobin/p/4590484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!