溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

bootstrap中bootstrap-editable和bootstrap-fileinput怎么用

發(fā)布時(shí)間:2021-08-09 14:15:11 來源:億速云 閱讀:119 作者:小新 欄目:web開發(fā)

這篇文章主要介紹了bootstrap中bootstrap-editable和bootstrap-fileinput怎么用,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

數(shù)據(jù)庫中為datetime類型,.net讀取數(shù)據(jù)已Json格式發(fā)回給前臺(tái)頁面:例如:使用bootstrap表格插件Ⅹ

 formatter: function (value, row, index) {
            var date = new Date(parseInt(value.slice(6)));
            return date.getFullYear() + '-' + parseInt(date.getMonth() + 1) + '-' + date.getDate() + " " + date.getHours() + ":" + date.getMinutes()+":"+date.getSeconds();
          }

使用bootstrap-editable時(shí)需要引用

<script src="~/Scripts/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<script src="~/Scripts/bootstraptable/dist/extensions/editable/bootstrap-table-editable.min.js"></script>

初始化時(shí):

{
          field: 'SkuPurchasePrice',
          title: '采購價(jià)',
          align: 'center',
          editable: {
            type: 'text',
            title: '采購價(jià)',
            validate: function (v) {
              if (v < 0) return '采購價(jià)不能小于0';
            }
          }
        }, {
          field: 'QtyAvailable',
          title: '庫存可用量',
          align: 'center',
          editable: {
            type: 'text',
            title: '庫存可用量',
            validate: function (v) {
              if (v < 0) return '庫存可用量不能小于0';
            },           
          },          
        }

事件:

onEditableSave: function (field, row, oldValue, $el) {
          $.ajax({
            type: 'post',
            url: "@Url.Action("EditNumber")",
            dataType: 'JSON',
            data: { "row": JSON.stringify(row) },
            success: function (data) {
              if (data.ResultType == 0) {
                toastr.success(data.Message);
              }
              else {
                toastr.warning(data.Message);
              }
            },
            error: function () {
              toastr.error("出錯(cuò)了,請(qǐng)聯(lián)系管理員");
            }
          });
        }

bootstrap-fileinput使用:

引用

<script src="~/Scripts/AdminLTE2.3.0/bootstrap/js/fileinput.min.js"></script>

初始化:

 <label class="control-label col-sm-1">商品上傳</label>
              <div class="col-sm-2"><input type="file" id="ProductsUpload" name="ProductsUpload" /></div>
              <div class="col-sm-1"><a href="~/ProductsExcel/DownloadTemplate?type=5" rel="external nofollow" target="_blank">下載模板</a></div>
function initFileInput(ctrlName) {
      var control = $('#' + ctrlName);
      control.fileinput({
        language: 'zh', //語言
        uploadUrl: "@Url.Action("ExcelLeadingIn")", //action
        autoReplace: true,
        maxFileCount: 1, //最大上傳數(shù)量
        allowedFileExtensions: ["xlsx", "xls"],
        browseClass: "btn btn-primary", //按鈕樣式
        dropZoneEnabled: false,
        enctype: 'multipart/form-data',
        showRemove: true, //是否顯示刪除按鈕
        showBrowse: true, //顯示瀏覽圖片按鈕
        msgFilesTooMany: "選擇上傳的文件數(shù)量({n}) 超過允許的最大數(shù)值{m}!",
        msgInvalidFileExtension:"只支持.xlsx和.xls文件的格式上傳",
        fileActionSettings: {
          showUpload: false, //預(yù)覽圖片上傳按鈕
          showRemove: false, //預(yù)覽圖片remove按鈕
          showZoom: false //關(guān)閉預(yù)覽圖片按鈕
        }
      }).on('fileuploaded', function (event, data, previewId, index) {//上傳圖觸發(fā)事件
        if (data.response.state == 1) {
          $('#excelLendingDiv h6').html($('#excelLendingDiv h6').html() + data.response.result+"<br/>");
        }
        else {
          toastr.error(data.response.result);
        }
      }).on('filecleared', function (event) {//remove觸發(fā)事件
        control.show();
      });
    }

 后臺(tái)上傳:

 [HttpPost]
    public ActionResult ExcelLeadingIn()
    {     
      var files = Request.Files;
      string name=files.Keys[0].ToString();
      if (files != null && files.Count > 0)
      {       
        var file = files[0];        
        string path = Server.MapPath("~/Content/excel/") + file.FileName;//文件保存在當(dāng)前域名下的Content/excel/中
        file.SaveAs(path);       
        string mess = OfferServer.ProductsDetail.InsertExcel(path,file.InputStream,name);
        return Json(new { state = 1, result = mess });
      }
      return Json(new { state = 0, result = "上傳發(fā)生錯(cuò)誤,請(qǐng)檢查后重試" });
    }

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“bootstrap中bootstrap-editable和bootstrap-fileinput怎么用”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI