• kendo upload必填验证


    
    
    @using Kendo.Mvc.UI
    @using StudentManage.Common.Helper
    @model StudentManage.Models.Home.ImportDataFromFileModel
    <style>
        .hiddenBox {
            display: block;
            border: none;
            width: 0;
            height: 0
        }
    </style>
    <script>
        var fileName;
        function onSelect(e) {
            fileName = $("#FileName").val() + getFileInfo(e);
            $("#FileName").val(fileName);
        }
        function onRemove(e) {
            fileName = $("#FileName").val().replace(getFileInfo(e), "");
            $("#FileName").val(fileName);
        }
    
        function getFileInfo(e) {
            return $.map(e.files, function (file) {
                var info = file.name;
                return info;
            }).join(", ");
        }
    </script>
    <form action="@Url.Action("ImportDataFromFile", "Home")" id="importForm" method="post" class="panel panel-default form-horizontal panel-body">
        <div class="form-group">
            @Html.RequiredIndicatorLabelFor(m=> m.FileName, new { @class = "col-sm-3 control-label no-padding-right" })
            <div class="col-sm-4">
                @Html.HiddenFor(m => m.DataSystemName, new { @class = "form-control" })
                @(Html.Kendo().Upload().Name("files").Multiple(false).HtmlAttributes(new { accept = ".xls,.xlsx" })
                                      .Events(events => events
                                          .Remove("onRemove")
                                          .Select("onSelect")
                              ))
                @Html.TextBoxFor(m => m.FileName, new { @class = "hiddenBox" })
                @Html.ValidationMessageFor(m => m.FileName)
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-5 col-sm-offset-3">
                <button class="btn  btn-info" type="button" id="submitBtn">
                    确定
                </button>
            </div>
        </div>
    </form>
    <script>
        $(function () {
            jQuery.validator.unobtrusive.parse();
            $('#importForm').removeData('validator');
            $('#importForm').removeData('unobtrusiveValidation');
            $.validator.unobtrusive.parse('#importForm');
            $("#submitBtn").click(function() {
                if (!$("#importForm").valid()){
                    return false;
                }
                $("#importForm").submit();
                return true;
            });
        });
    </script>
    
    
    
     

    Action

            #region 导入导出数据
            [HttpGet]
            public ActionResult ImportDataFromFile(string dataSystemName)
            {
                ImportDataFromFileModel model = new ImportDataFromFileModel()
                {
                    DataSystemName = dataSystemName
                };
                return PartialView(model);
            }
    
            [HttpPost]
            public async Task<ActionResult> ImportDataFromFile(IEnumerable<HttpPostedFileBase> files)
            {
                //DataTable dataTable = await NpoiHelper.ExcelToDataTable("Sheet1", true, files.First());
                //for (int i = 0; i < dataTable.Rows.Count; i++)
                //{
    
                //    //var enterprise = new Enterprise();
                //    //enterprise.Id = Guid.NewGuid();
                //    //if (dataTable.Rows[i][enterpriseNameColumn] != null)
                //    //{
                //    //    var content = dataTable.Rows[i][enterpriseNameColumn]?.ToString().Trim();
                //    //    var clearName = content.Length < 100 ? content : content.Substring(0, 100);
                //    //    if (enterpriseNames.Contains(clearName)) continue;
                //    //    enterprise.EnterpriseName = clearName;
                //    //}
                //}
                return RedirectToAction("Index","StudentManage");
            }
    
    
            #endregion
  • 相关阅读:
    简单的jQuery扩展函数-让函数缓冲执行
    Sharepoint更新字段触发工作流(无代码)
    jQuery Multi-TouchWipe / Multi-TouchZoom
    jQuery WipeTouch
    当页弹出对话框的实现
    SlidesJS的使用
    三级浮动菜单的实现
    UI中经常出现的下拉框下拉自动筛选效果的实现
    图片预加载,按需加载
    项目新的需求,网页的自适应交付/响应式交付 Responsive/Adaptive Delivery
  • 原文地址:https://www.cnblogs.com/taoshengyujiu/p/10327756.html
Copyright © 2020-2023  润新知