日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

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

發(fā)布時間:2023/12/18 asp.net 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用easyui-filebox上传Excel文件(ASP.NET MVC)[附源码下载] 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

MVC的cshtml源碼:

@{ViewBag.Title = "djk8888"; } <link href="~/js/easyui/themes/default/easyui.css" rel="stylesheet" /> <link href="~/js/easyui/themes/icon.css" rel="stylesheet" /> <script src="~/js/easyui/jquery.min.js"></script> <script src="~/js/easyui/jquery.easyui.min.js"></script> <script type="text/javascript">$(function () {//設(shè)置easyui-filebox$("#file1").filebox({//required: true,//是否必填//multiple: true,//是否多選(默認(rèn)false,單選)//buttonAlign: 'left',//按鈕出現(xiàn)的位置(默認(rèn)right)width: '300px',//寬度prompt: '選擇文件...',//提示信息buttonText: '選擇',//按鈕文字validType: ['fileSize[1024,"kb"]'],//文件大小限制(好像沒卵用)accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel',//限制文件類型(也好像沒卵用)onChange: function () {$("#btnUpload").hide();//隱藏上傳按鈕//判斷選擇的文件是不是Excelvar temp = $("#file1").filebox('getValue');if (temp != '') {var arr = temp.split('.');if (arr.length > 1) {var expanded_name = arr[arr.length - 1].toLowerCase();//取得文件擴(kuò)展名if (expanded_name == "xls" || expanded_name == "xlsx") {//確實是Excel文件//判斷文件大小var f = document.getElementById("filebox_file_id_2").files;//用F12查看easyui生成的file控件的idvar size = f[0].size; //單位bytevar size = (size / 1024).toFixed(2);//單位kbvar maxFileSize = 1024;//1mb=1024kbif (size > maxFileSize) {$("#btnUpload").hide();//隱藏上傳按鈕alert("文件大小:" + size + "KB,超過最大限制:" + maxFileSize + "KB");$("#file1").filebox('reset');return;}else {$("#btnUpload").show();//顯示上傳按鈕準(zhǔn)備上傳}}else {//選擇了其他類型的文件$("#btnUpload").hide();//隱藏上傳按鈕alert("請選擇Excel文件!");$("#file1").filebox('reset');return;}}else {//選擇了無擴(kuò)展名的文件$("#btnUpload").hide();alert("請選擇Excel文件!!");$("#file1").filebox('reset');return;}}},});//上傳文件到服務(wù)器:$("#btnUpload").click(function () {$('#fm').form('submit', {url: '/Easyui/UploadExcel',success: function (result) {alert(result);$("#file1").filebox('reset');$("#btnUpload").hide();//隱藏上傳按鈕}});});}); </script> <h2>用easyui-filebox上傳Excel文件(ASP.NET MVC)</h2> <form id="fm" method="post" enctype="multipart/form-data"><input id="file1" class="easyui-filebox" name="file1" /><input type="button" id="btnUpload" value="上傳" style="display:none;" /> </form>MVC的Controller源碼:

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc;namespace jqueryfileupload.Views.Home {public class EasyuiController : Controller{public ActionResult Index(){return View();}private string StorageRoot{get { return Path.Combine(Server.MapPath("~/Files")); }}public ActionResult UploadExcel(){try{var file = Request.Files["file1"];//file1就是easyui-filebox的namevar 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);}}} }
本例配套源碼下載: http://download.csdn.net/download/djk8888/10167119


用jQuery-File-Upload上傳Excel文件(ASP.NET MVC) 傳送門:http://blog.csdn.net/djk8888/article/details/78835131

總結(jié)

以上是生活随笔為你收集整理的用easyui-filebox上传Excel文件(ASP.NET MVC)[附源码下载]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。