ASP.NET MVC- Upload File的例子
上传文件是一项基本功能,一定要了解的。先来看一下使用ASP.NET MVC实现简单的上传。
一、简单的例子
Controller的例子
public ActionResult UploadDemo()
{
return View();
} public ActionResult FileUpload()
{
HttpPostedFileBase file = Request.Files["file"];
if (file != null)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(file.FileName));
file.SaveAs(filePath); Response.Write("<script>alert('上传成功');location.href='/Index/UploadDemo' </script>");
}
else
{
Response.Write("<script>alert('上传失败');location.href='/Index/UploadDemo' </script>");
} return null;
}
对应的View视图
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>UploadDemo</title>
</head>
<body>
<div>
<h2>
上传例子</h2>
@using (Html.BeginForm("FileUpload", "Index", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="uploadFile" />
}
</div>
</body>
</html>
ASP.NET MVC- Upload File的例子的更多相关文章
- ASP.Net MVC upload file with record & validation - Step 6
Uploading file with other model data, validate model & file before uploading by using DataAnnota ...
- Asp.net mvc 3 file uploads using the fileapi
Asp.net mvc 3 file uploads using the fileapi I was recently given the task of adding upload progress ...
- asp.net mvc return file result
asp.net mvc返回文件: public ActionResult ExportReflection(string accessToken) { var reflections = GetCms ...
- asp.net mvc使用jwt简单例子
Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准.该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场景.JWT的声 ...
- Asp.net MVC 控制器ActionResult的例子
ActionResult 父类型 ViewResult View() 多重载应用 PartialViewResult PartialView() 部分试图 New EmptyResult() 空 如 ...
- asp.net mvc 5 单元测试小例子
using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTest ...
- ASP.NET MVC 例子演示如何在 Knockout JS 的配合下,使用 TypeScript 。
一个简单的 ASP.NET MVC 例子演示如何在 Knockout JS 的配合下,使用 TypeScript . 前言 TypeScript 是一种由微软开发的自由和开源的编程语言.它是JavaS ...
- 【转】ASP.NET MVC框架下使用MVVM模式-KnockOutJS+JQ模板例子
KnockOutJS学习系列----(一) 好几个月没去写博客了,最近也是因为项目紧张,不过这个不是借口,J. 很多时候可能是因为事情一多,然后没法静下来心来去写点东西,学点东西. 也很抱歉,突然看到 ...
- ASP.NET MVC file download sample
ylbtech- ASP.NET MVC:ASP.NET MVC file download sample 功能描述:ASP.NET MVC file download sample 2,Techno ...
随机推荐
- QCon 2015 阅读笔记 - 其他精选主题
QCon 2015阅读笔记 QCon 2015 阅读笔记 - 移动开发最佳实践 QCon 2015 阅读笔记 - 团队建设 QCon 2015 阅读笔记 - 其他精选主题 以前分享过两个主题:移动开发 ...
- python练习程序(c100经典例13)
题目: 打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数. for i in range(100,1000): a=i/100; b=(i/10)%10; c=i%1 ...
- 【JavaScript学习笔记】if使用
<html> <body> <script language="JavaScript"> var a=4; var b=2; if(a==3) ...
- Linux Shell编程(3):数组
http://snailwarrior.blog.51cto.com/680306/154704 BASH只支持一维数组,但参数个数没有限制. 声明一个数组:declare -a array (其 ...
- QR二维码(转)
二维码又称QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型:比如:字符,数字, ...
- WINHEX 使用教程
Winhex有完善的分区管理功能和文件管理功能,能自动分析分区链和文件簇链,能对硬盘进行不同方式不同程度的备份,甚至克隆整个硬盘:它能够编 辑任何一种文件类型的二进制内容(用十六进制显示)其磁盘编辑器 ...
- Delphi 实现16进制转字符串及字符串(中文)转16进制
//-----------------------------------------------//16进制字符转整数,16进制字符与字符串转换中间函数//--------------------- ...
- 可进行JavaScript代码测试与调试的12个网站
概述:JavaScript是网站前端开发最为重要的一门编程语言,本文收集了能够在线测试与调试JavaScript代码的12个网站 1.JS Bin JS bin是一个为JavaScript和CSS爱好 ...
- 使用源码编译wxpython-基于python2.7
1.前言 本文主要讲述在linux环境下进行编译wxpython,在windows下面安装wxpython很简单,只要下载,然后直接执行exe文件,下一步下一步即可安装,在linux下面,则具有很多步 ...
- 【LeetCode】28 - Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...