Bootstrap-FileInput组件的简单Demo
2024-10-01 15:21:20
官网:
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 > )
{
try
{
var file = files[];
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);
}
最新文章
- PHP开发中的缓存技术汇总
- 添加了有道生词本的 chrome google翻译扩展和有道翻译扩展
- WinForm 使用 HttpUtility
- Linux:系统的密码忘记了,登录不上
- Windows Embedded Compact 2013升级:VS2013也能编译
- cache—主存—辅存三级调度模拟
- AFNetworiking与ASIHttpRequest对比
- 怎样在小方框上打对号 小方框内打对勾 word 方框打对勾
- javaweb利用filter拦截请求
- 基本数据类型 字典 dict
- 深度学习(PYTORCH)-3.sphereface-pytorch.lfw_eval.py详解
- 常用nginx rewrite重定向-跳转实例:
- HashMap实现原理分析--面试详谈
- js上传插件uploadify自动检测不到flash控件的问题
- tengine 增加ngx_http_cache_purge_module 模块
- vlc 网页插件的 使用与控制 API http://www.xuebuyuan.com/2224602.html
- php上传文件涉及到的参数
- 使用AHKActionSheet
- 【CF739E】Gosha is hunting(动态规划,凸优化)
- 视图 b
热门文章
- m_Orchestrate learning system---十六、如何快速在一堆字符图标中找到所需
- php 设计模式之观察者模式(订阅者模式)
- hdoj--1384--Intervals(差分约束)
- caffe中LetNet-5卷积神经网络模型文件lenet.prototxt理解
- html单行、多行文本溢出隐藏
- 图论之tarjan缩点
- oracle 11g rac for linux add node (oracle 11g rac 节点添加)
- 10:Challenge 3(树状数组直接修改)
- the prblem 3n+1
- Spring Framework 开发参考手册中文(在线HTML)