最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JQuery fileupload插件實(shí)現(xiàn)文件上傳功能

 更新時(shí)間:2016年03月18日 16:21:11   作者:填坑女俠  
這篇文章主要介紹了JQuery fileupload插件實(shí)現(xiàn)文件上傳功能的相關(guān)資料,需要的朋友可以參考下

道理相通,我簡單分享下在.net MVC下的實(shí)裝。

1.制作Model類

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

namespace RCRS.WebApp.LG.EM.Models
{
 //----------------------------------------------------------------
 /// <summary>
 /// Import畫面用
 /// </summary>
 //----------------------------------------------------------------
 public class tmp_UploadFile
 {
  /// <summary></summary>
  public HttpPostedFileBase FileName { get; set; }
 }
}

2.實(shí)裝controller里的對(duì)應(yīng)方法,我這個(gè)處理邏輯比較復(fù)雜,懶得修改了,反正就這個(gè)意思

//----------------------------------------------------------------
  /// <summary>
  /// アップロード
  /// </summary>
  /// <returns></returns>
  //----------------------------------------------------------------
  [HttpPost]
  public virtual ActionResult UploadFile()
  {
   HttpPostedFileBase uploadedFile = Request.Files["FileName"];
   string message = "アップロード失敗しました。";
   bool isUploaded = false;
   string path = "";
   string dateTimeNow = DateTime.Now.ToString("yyMMdd-hhmmss");
   string userName = User.Identity.GetUserName();
   string uploadMsg = string.Empty;

   if (uploadedFile != null && uploadedFile.ContentLength != 0)
   {
    string pathForSaving = Server.MapPath("~/App_Data/Uploaded/");
    try
    {
     if (BsnssBihin.IsExcel(uploadedFile.FileName))
     {
      path = System.IO.Path.Combine(pathForSaving, dateTimeNow + "_" + uploadedFile.FileName);
      uploadedFile.SaveAs(path);
      isUploaded = BsnssBihin.UploadBihinChange(path, userName, ref uploadMsg);
      if (isUploaded)
      {
       message = "アップロード成功しました!" + "\n" + uploadMsg;
       Logger.Info("[成功]備品アップロード, " + dateTimeNow + ", " + "[" + userName + "]" + "[" + path + "]" + uploadMsg);
      }
      else
      {
       message = "アップロード失敗しました。" + "\n" + uploadMsg;
       Logger.Info("[失敗]備品アップロード, " + dateTimeNow + ", " + "[" + userName + "]" + "["+path + "]" + uploadMsg);
      }
     }
     else
     {
      message = "ファイルの形式は不正です。";
     }
    }
    catch (Exception ex)
    {
     message = string.Format("失敗しました: {0}", ex.Message);
     Logger.Info("[失敗]備品アップロード: " + ex.Message + dateTimeNow + ", " + "[" + userName + "]" + "[" + path + "]");
    }
   }
   return Json(new { isUploaded = isUploaded, message = message }, "text/html");
  }

3.頁面的實(shí)裝

@model RCRS.WebApp.LG.EM.Models.tmp_UploadFile
<table align="center" style="margin-bottom:200px">
 <tr>
  <td>
   <div style="width:470px">
    <input type="text" id="tbx-file-path" value="ファイルを選択してください" readonly="readonly" />
   </div>
  </td>
  <td>
   <div style="width: 60px">
    <span class="btn btn-primary fileinput-button">
     <span>選 択</span>
     @Html.TextBoxFor(m => m.FileName, new { id = "file-upload", type = "file", accept = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" })
    </span>
   </div>
  </td>
  <td>
   <div style="width:60px">
    <a class="btn btn-primary" href="#" id="hl-start-upload">アップロード</a>
   </div>
  </td>
 </tr>
</table>

<div id="loadingOver" class="loadingOver"></div>
<div id="dvloader" class="dvloader">
 <span class="label label-info" style="align-content:center"> 処理中、少々お待ちください</span><br />
 <br />
 <img id="loadingGif" src="../Content/img/loader.gif" alt="" />
</div>

@section scripts{
 @Scripts.Render("~/bundles/jquery")
 @Scripts.Render("~/bundles/jqueryui")
 @Scripts.Render("~/bundles/jqueryval")
 @Scripts.Render("~/bundles/common")
 @Scripts.Render("~/bundles/fileupload")
 <script type="text/javascript">
  var data_upload;
  $(document).ready(function () {
   'use strict';
   $('#file-upload').fileupload({
    url: '../Bihin/UploadFile',
    dataType: 'json',
    add: function (e, data) {
     data_upload = data;
    },
    done: function (event, data) {
     if (data.result.isUploaded) {
      $("#tbx-file-path").val("ファイルを選択してください");
      data_upload = "";
     }

     $("#dvloader").css("display", "none");
     $("#loadingOver").css("display", "none");

     alert(data.result.message);
    },
    fail: function (event, data) {
     data_upload = "";
     if (data.files[0].error) {

      $("#dvloader").css("display", "none");
      $("#loadingOver").css("display", "none");

      alert(data.files[0].error);
     }
    }
   });
  });

  $("#hl-start-upload").on('click', function () {
   if (data_upload) {
    $("#dvloader").css("display", "block");
    $("#loadingOver").css("display", "block");
    data_upload.submit();
   }
   return false;
  });

  $("#file-upload").on('change', function () {
   $("#tbx-file-path").val(this.files[0].name);
  });

  </script>
}

√,就是這個(gè)樣子
還附贈(zèng)了一個(gè)簡易loding的實(shí)現(xiàn)
貼出CSS代碼:

.dvloader {
 display:none;
 position:absolute;
 top:40%;
 left:40%;
 width:20%;
 height:20%;
 z-index:1001;
 text-align:center;
 font-size:1.5em;
}

.loadingOver {
 display:none;
 position:absolute;
 top:0;
 left:0;
 width:100%;
 height:100%;
 background-color:#f5f5f5;
 opacity:0.5;
 z-index:1000;
}

這里,多說一嘴:
關(guān)于input 的accept屬性,這里只想讀入Excel,所以
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel

更多精彩內(nèi)容,請(qǐng)點(diǎn)擊《jQuery上傳操作匯總》,進(jìn)行深入學(xué)習(xí)和研究。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • jQuery背景插件backstretch使用指南

    jQuery背景插件backstretch使用指南

    Backstretch是一款簡單的jQuery插件,可以幫助你給網(wǎng)頁添加一個(gè)動(dòng)態(tài)的背景圖片,可以自動(dòng)調(diào)整大小適應(yīng)屏幕的尺寸,當(dāng)然這樣做的缺點(diǎn)是當(dāng)圖片尺寸比屏幕小的時(shí)候,圖片會(huì)因?yàn)樽詣?dòng)延伸而變形,所以我們可以勁量使用高分辨率大尺寸的圖片做背景,更重要的是支持圖片的自動(dòng)切換
    2015-04-04
  • google jQuery 引用文件,jQuery 引用地址集合(jquery 1.2.6至jquery1.5.2)

    google jQuery 引用文件,jQuery 引用地址集合(jquery 1.2.6至jquery1.5.2)

    很多網(wǎng)站都是使用這種方式引入,客戶的瀏覽器可能已經(jīng)緩存過了 jquery。可以直接調(diào)用本地的,速度更快
    2011-04-04
  • 基于jQuery的倒計(jì)時(shí)插件代碼

    基于jQuery的倒計(jì)時(shí)插件代碼

    jQuery倒計(jì)時(shí)插件,主要用來限時(shí)購買,需要的朋友可以參考下。
    2011-05-05
  • Jquery 動(dòng)態(tài)添加元素并添加點(diǎn)擊事件實(shí)現(xiàn)過程解析

    Jquery 動(dòng)態(tài)添加元素并添加點(diǎn)擊事件實(shí)現(xiàn)過程解析

    這篇文章主要介紹了Jquery 動(dòng)態(tài)添加元素并添加點(diǎn)擊事件實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • jquery實(shí)現(xiàn)提示語淡入效果

    jquery實(shí)現(xiàn)提示語淡入效果

    本篇文章主要介紹了jquery實(shí)現(xiàn)提示語淡入效果的實(shí)例,具有很好的參考價(jià)值。下面跟著小編一起來看下吧
    2017-05-05
  • jQuery插件編寫步驟詳解

    jQuery插件編寫步驟詳解

    這篇文章主要介紹了jQuery插件編寫步驟,詳細(xì)分析了jQuery實(shí)現(xiàn)插件功能的具體步驟與相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-06-06
  • Jquery遍歷Json數(shù)據(jù)的方法

    Jquery遍歷Json數(shù)據(jù)的方法

    這篇文章主要介紹了Jquery遍歷Json數(shù)據(jù)的方法,涉及jQuery遍歷json格式數(shù)據(jù)的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • 使用jQuery操作Cookies的實(shí)現(xiàn)代碼

    使用jQuery操作Cookies的實(shí)現(xiàn)代碼

    Cookies是一種能夠讓網(wǎng)站服務(wù)器把少量數(shù)據(jù)儲(chǔ)存到客戶端的硬盤或內(nèi)存,或是從客戶端的硬盤讀取數(shù)據(jù)的一種技術(shù)
    2011-10-10
  • 取消選中單選框radio的三種方式示例介紹

    取消選中單選框radio的三種方式示例介紹

    本文依賴于jQuery,其中第一種,第二種方式是使用jQuery實(shí)現(xiàn)的,第三種方式是基于JS和DOM實(shí)現(xiàn)的,感興趣的朋友可以了解下
    2013-12-12
  • jQuery EasyUI API 中文文檔 - NumberBox數(shù)字框

    jQuery EasyUI API 中文文檔 - NumberBox數(shù)字框

    jQuery EasyUI API 中文文檔 - NumberBox數(shù)字框使用介紹,需要的朋友可以參考下。
    2011-10-10

最新評(píng)論

高雄市| 建湖县| 辰溪县| 舟山市| 苗栗县| 米林县| 绥芬河市| 肥西县| 保山市| 天长市| 长宁县| 西乡县| 高淳县| 册亨县| 花莲县| 肇州县| 霍林郭勒市| 逊克县| 广昌县| 政和县| 高淳县| 航空| 阜康市| 独山县| 万安县| 德清县| 巴楚县| 简阳市| 阜新市| 噶尔县| 高平市| 米脂县| 抚松县| 大足县| 神池县| 吉水县| 罗定市| 巩留县| 双辽市| 汝城县| 红原县|