标签:remove bootstrap string exce jpg default ring 代码 returns
<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>
/// <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); }
标签:remove bootstrap string exce jpg default ring 代码 returns
原文地址:http://www.cnblogs.com/mahuanpeng/p/5998711.html