asp.net mvc上传文件
2015-06-20 13:59
726 查看
在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");
}
@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");
}
相关文章推荐
- ABP(现代ASP.NET样板开发框架)系列之9、ABP设置管理
- ABP(现代ASP.NET样板开发框架)系列之10、ABP领域层——实体
- ASP.NET MVC5利用EF,反向自动生成数据库
- 基于Raspberry Pi Raspbian 的 Hadoop 安装
- ASP.NET性能优化之让浏览器缓存动态网页
- ASP.NET MVC 开启AJAX跨域请求
- Asp.NET的目的是学习
- 【ASP.NET】初次见面
- 17.AspxGridView服务器事件列表
- popupWin 属性及用法介绍 ASP.NET控件,仿QQ,msn右下角弹出窗口
- ASP.NET MVC中将控制器分离到类库的实现(转)
- ASP.NET WebAPI RC 竟然不支持最常用的json传参
- 适合ASP.NET Web API使用的场景
- 改善ASP.NET Web API性能的八项技术
- ASP.Net增删查改写的一个通讯录系统---ShinePans
- ASP.NET Web API 用IE浏览器访问下载文件问题
- ASP.NET WebApi 文件上传功能
- Asp.net MVC Session过期异常的处理
- ASP.NET MVC中的Session设置
- web渗透(asp数字型注入模拟实战)