Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
Mvc return custom view – 扎老铁
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
class="post-51739 post type-post status-publish format-standard hentry">

Mvc return custom view

[Privilege(Privileges.Management.CustomerAgreement.CreateAndEdit)]
       [HttpPost]
       public ActionResult ImportWorkbook()
       {
           var allFiles = Request.Files;
           if (allFiles == null || allFiles.Count == 0)
           {
               ModelState.AddModelError("filePath", "请选择文件");
               return Failure();
           }
           for (int i = 0; i < allFiles.Count; i++)
           {
               if (allFiles[i] == null || allFiles[i].ContentLength == 0)
               {
                   ModelState.AddModelError("filePath", "您选择的文件内容为空,请重新选择");
                   return Failure();
               }
               string name = System.IO.Path.GetExtension(allFiles[i].FileName);
               if (string.IsNullOrWhiteSpace(name) || string.Compare(name, ".xls", StringComparison.OrdinalIgnoreCase) != 0)
               {
                   if (string.Compare(name, ".xlsx", StringComparison.OrdinalIgnoreCase) == 0)
                   {
                       ModelState.AddModelError("filePath", "请选择后缀为 .xls (EXCEl 2003) 的文件,你可以在 EXCEL 中将本文件另存为 .xls 格式。");
                   }
                   else
                   {
                       ModelState.AddModelError("filePath", "请选择后缀为 .xls 的文件");
                   }
                   return Failure();
               }
           }
           //    if (string.IsNullOrWhiteSpace(name) ||
           //        ((string.Compare(name, ".xls", StringComparison.OrdinalIgnoreCase) != 0) &&
           //        (string.Compare(name, ".xlsx", StringComparison.OrdinalIgnoreCase) != 0))
           //        )
           //    {
           //        ModelState.AddModelError("filePath", "请选择后缀为 .xls 或者 .xlsx 的文件");
           //        return Failure();
           //    }
           //}

           var result = CustomerAgreementImportService.Instance.ImportExcelFile(base.WorkContext, allFiles[0].InputStream, allFiles[0]);
           if (result.HasError)
           {
               return Failure().AddView("ErrorItemsHTML", PartialView("_ImportErrors", result));
           }
           else if (result.IsEmpty)
           {
               ModelState.AddModelError("filePath", "没有识别到任何数据");
               return Failure();
           }
           return Success("导入成功").RedirectUrl(Url.Action("List", "CustomerAgreement"));
       }

 

 

 

发表评论

电子邮件地址不会被公开。