Bootstrap-FileInput组件的简单Demo

官网:
 
HTML页面:
引用:
<link href="~/BootstrapComponent/css/fileinput.css" rel="stylesheet" />
<script src="~/BootstrapComponent/js/fileinput.js"></script>
<script src="~/BootstrapComponent/js/locales/zh.js"></script>
<!--容器-->
<input id="inputFile" type="file" class="file" data-preview-file-type="text" name="file">
<!--JS代码-->
<script>
    //初始化fileinput控件
    $("#inputFile").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["jpg", "png", "gif"],
            browseClass: "btn btn-primary", //按钮样式 
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
    });
</script>

 

fileinput.js文件参数修改:
$.fn.fileinput.defaults = {
language: 'en',
showCaption: true,
showBrowse: true,
showPreview: true,
showRemove: true,
showUpload: false, //若为同步提交,无需显示组件的上传按钮
showCancel: true,
showClose: true,
   ...
  }
MVC控制器:
        /// <summary>
        /// MVC文件上传后台方法
        /// </summary>
        /// <returns></returns>
        public JsonResult FileUpload()
        {
            string text = "位置错误!";
            bool isSuccess = false;
            var files = Request.Files;          
            if (files != null && files.Count > 0)
            {
                try
                {
                    var file = files[0];
                    var fileName = file.FileName;
                    var filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "image", fileName);    //绝对路径
                    file.SaveAs(filePath);
                    isSuccess = true;
                    text = "上传成功!";
                }
                catch (Exception e)
                {
                    text = e.Message;
                }
            }
            return Json(new { Success = isSuccess, Message = text }, JsonRequestBehavior.AllowGet);
        }

 

转载于:https://www.cnblogs.com/mahuanpeng/p/5998711.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值