在做Excel文件上传和下载时,原生文件输入框太不美观,从网上找的bootstrap fileinput还是挺漂亮的,

需要引用的文件  //4.fileUpload
            bundles.Add(new ScriptBundle("~/Script/FileUploadJs").Include(
                        "~/Scripts/FileUpload/zh.js",
                        "~/Scripts/FileUpload/fileinput.min.js"));
            bundles.Add(new StyleBundle("~/Css/FileUploadCss").Include(
                         "~/Css/FileUpload/fileinput.min.css"));

html中嵌入

<div class="modal fade" id="ImportModel" tabindex="-1" role="dialog" aria-labelledby="#myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">从Execl导入员工</h4>
            </div>
            <div class="modal-body">
                <form id="formtt" class="form-horizontal">
                    <div class="form-group" style="margin-top:15px">
                        <a href="~/Excel/Template/UserTemplate.xlsx" class="form-control" style="border:none;">下载导入模板</a>
                         <input id="txt_file" type="file" multiple class="file" data-overwrite-initial="false">
                        <br>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
            </div>
        </div>
    </div>
</div>

相关Js代码如下

//初始化fileinput
var FileInput = function () {
    var oFile = new Object();
    //初始化fileinput控件(第一次初始化)
    oFile.Init = function (ctrlName, uploadUrl) {
        var control = $('#' + ctrlName);

        //初始化上传控件的样式
        control.fileinput({
            uploadUrl: uploadUrl, //上传的地址
            allowedFileExtensions: ['jpg', 'gif', 'png','xlsx'],//接收的文件后缀
            showUpload: true, //是否显示上传按钮
            showCaption: false,//是否显示标题
            overwriteInitial: false,
            browseClass: "btn btn-primary", //按钮样式
            dropZoneEnabled: false,//是否显示拖拽区域
            enctype: 'multipart/form-data',
            validateInitialCount: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",
        });

        //导入文件上传完成之后的事件
        $("#txt_file").on("fileuploaded", function (event, data, previewId, index) {
            $("#div_startimport").show();
        });
    }
    return oFile;
};

当然初始化时可设置的选项远不止这些,组件功能强大,灵活性也比较强

做后端,js代码基本的能写,html布局及美化实在是不咋样,所以基本都是借助网上开放的组件资源,去学习拿来用

下篇文章介绍一款开源的操作Excel文件的组件EPPlus,用着感觉比NPOI方便些

文件上传(bootstrap fileinput)的更多相关文章

  1. Bootstrap 文件上传插件 FileInput的使用问题

    : 在使用bootstrap的文件上传插件fileinput http://plugins.krajee.com/file-input的预览功能时,删除预览图片在 bootstrap 模态框中没有用, ...

  2. 基于Ajax的文件上传使用FileInput插件(使用谷歌翻译作者的原文,大致意思是对的,自己把握)

    bootstrap-fileinput 说明文档:http://plugins.krajee.com/file-input 有许多人希望学习使用bootstrap-fileinput jQuery插件 ...

  3. Bootstrap Fileupload 文件上传

    1.在jsp中引入css与js文件, <link href="${ctx}/plugins/fileup/css/fileinput.css" media="all ...

  4. ***文件上传控件bootstrap-fileinput的使用和参数配置说明

    特别注意:    引入所需文件后页面刷新查看样式奇怪,浏览器提示错误等,可能是因为js.css文件的引用顺序问题,zh.js需要在fileinput.js后面引入.bootstrap最好在filein ...

  5. JS组件系列——Bootstrap文件上传组件:bootstrap fileinput

    前言:之前的三篇介绍了下bootstrap table的一些常见用法,发现博主对这种扁平化的风格有点着迷了.前两天做一个excel导入的功能,前端使用原始的input type='file'这种标签, ...

  6. .net core版 文件上传/ 支持批量上传,拖拽以及预览,bootstrap fileinput上传文件

    asp.net mvc请移步 mvc文件上传支持批量上传,拖拽以及预览,文件内容校验 本篇内容主要解决.net core中文件上传的问题  开发环境:ubuntu+vscode 1.导入所需要的包:n ...

  7. 结合bootstrap fileinput插件和Bootstrap-table表格插件,实现文件上传、预览、提交的导入Excel数据操作流程

    1.bootstrap-fileinpu的简单介绍 在前面的随笔,我介绍了Bootstrap-table表格插件的具体项目应用过程,本篇随笔介绍另外一个Bootstrap FieInput插件的使用, ...

  8. 基于bootstrap的上传插件fileinput实现ajax异步上传功能(支持多文件上传预览拖拽)

    首先需要导入一些js和css文件 ? 1 2 3 4 5 6 <link href="__PUBLIC__/CSS/bootstrap.css" rel="exte ...

  9. BootStrap fileinput.js文件上传组件实例代码

    1.首先我们下载好fileinput插件引入插件 ? 1 2 3 <span style="font-size:14px;"><link type="t ...

随机推荐

  1. 【51.27%】【codeforces 604A】Uncowed Forces

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. [JS Compose] 1. Refactor imperative code to a single composed expression using Box

    After understanding how Box is, then we are going to see how to use Box to refacotr code, to un-nest ...

  3. 事件处理之一:两种方式:监听器与回调 分类: H1_ANDROID 2013-10-31 10:26 3250人阅读 评论(0) 收藏

    Android组件的事件处理有2种方式: 1.基于监听器的事件处理方式:先定义组件,然后为组件设定监听器. 详见http://blog.csdn.net/jediael_lu/article/deta ...

  4. 本人录制的视频资源(C/C++、Go、Qt、Linux等)

    持续更新-- 编程语言 C语言开发实战:http://pan.baidu.com/s/1qXAP4x2 C语言贪吃蛇:https://pan.baidu.com/s/1pLRZIuJ C提高:http ...

  5. 基于 Android NDK 的学习之旅-----JNI LOG 打印

    程序都是调出来的. 下面我介绍下JNI层的log打印方法的使用,类似与Android sdk提供的log 1.Android 应用层 MainActivity.java 主要功能代码 a)       ...

  6. [Ramda] Refactor to Point Free Functions with Ramda using compose and converge

    In this lesson we'll take some existing code and refactor it using some functions from the Ramda lib ...

  7. Thrift是一款由Fackbook开发的可伸缩、跨语言的服务开发框架

    这段时间,一直在整理公司的内部 rpc 服务接口,面临的一个问题就是:由于公司内部的系统由几个不同的语言编写的.C# ,java,node.js 等,如何实现这些内部系统之间的接口统一调用,确实是比较 ...

  8. [Ramda] Sort, SortBy, SortWith in Ramda

    The difference between sort, sortBy, sortWith is that: 1. sort: take function as args. 2. sortBy: ta ...

  9. Erlang 聊天室程序

    Erlang 聊天室程序( 一) Erlang 聊天室程序(二) 客户端的退出 Erlang 聊天室程序(三) 数据交换格式---json的decode Erlang 聊天室程序(四) 数据交换格式- ...

  10. 版本控制(1)——SVN

    一.工具下载 下载SVN: http://subversion.apache.org/ 我们选择Windows系统中的可视化的VisualSVN 如下图,左边是客户端,右边是服务器端,我们下载服务器端 ...