用jQuery-File-Upload上传Excel文件(ASP.NET MVC)[附源码下载]

MVC的cshtml部分:

@{
    ViewBag.Title = "djk8888";
}









用jQuery-File-Upload上传Excel文件(ASP.NET MVC)

ASP.NET MVC的Controller部分

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace jqueryfileupload.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult UploadFiles()
        {
            try
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];
                    var fullPath = Path.Combine(StorageRoot, Path.GetFileName(file.FileName));
                    file.SaveAs(fullPath);
                }
                return Content("上传成功!");
            }
            catch (Exception ex)
            {
                return Content(ex.ToString() + "\r\n" + ex.Message + "\r\n" + ex.Source + "\r\n" + ex.StackTrace);
            }       
        }
        private string StorageRoot
        {
            get { return Path.Combine(Server.MapPath("~/Files")); }
        }      
    }
}

配套源代码下载地址:

http://download.csdn.net/download/djk8888/10163404

http://download.csdn.net/download/djk8888/10167119 [推荐]

吐槽一下:我就是想让大家0分下载,但是现在CSDN的下载积分规则变了,我也只好呵呵了


用easyui-filebox上传Excel文件(ASP.NET MVC) 传送门:http://blog.csdn.net/djk8888/article/details/78859688

你可能感兴趣的:(html,ASP.NET代码)