0

我的 HTML 代码:

<div class="col-md-6">
    <img ngf-src="!picFile.$error && picFile" style="height: 150px; width: 200px;">
    <input type="file" ngf-select ng-model="picFile" name="file"
                       accept="image/*" ngf-max-size="2MB"><b>Picture</b><br />
</div>
            
<div class="col-md-6">
    <img ngf-src="!sigFile.$error && sigFile" style="height: 150px; width: 200px;">
    <input type="file" ngf-select ng-model="sigFile" name="file"
                       accept="image/*" ngf-max-size="2MB"><b>Signature</b><br />
</div>

还有我的角码

$scope.SaveNewJoinHolder = function (picFile, sigFile) {
    if (investor_validity == 1) {
        if ($scope.newJoinHolderForm.$valid) {
            if (typeof $scope.newJoinHolder.DOB == undefined) {
                $scope.newJoinHolder.DOB = null;
            }
            else {
                var datefilter = $filter('date');
                $scope.newJoinHolder.DOB = datefilter($scope.newJoinHolder.DOB, 'dd/MM/yyyy');
                $scope.newJoinHolder.birth_date = dateconfigservice.FullDateUKtoDateKey($scope.newJoinHolder.DOB);
            }
            Upload.upload(
              {
                  url: '/InvestorManagement/JoinHolder/SaveNewJoinHolder',
                  method: 'POST',
                  fields: $scope.newJoinHolder,
                  file: { picFile: picFile, sigFile: sigFile },
                  async: true

              })
              .success(function () {
                  toastr.success('Submitted Successfully');
               }).error(function () {
                  toastr.success('Failed');
               });
            }
        }
    };

我调试了代码,在调试时我得到了两个文件。但它没有调用我的 C# 方法

public JsonResult SaveNewJoinHolder(tblJoinHolder joinHolder, HttpPostedFileBase picFile, HttpPostedFileBase sigFile)
{
    joinHolderFactory = new JoinHolderFactory();
    
    try
    {
        joinHolder.membership_id = SessionManger.BrokerOfLoggedInUser(Session).membership_id;
        joinHolder.changed_user_id = User.Identity.GetUserId();
        joinHolder.changed_date = DateTime.Now;
        joinHolder.is_dirty = 1;
        byte[] image = new byte[picFile.ContentLength];
        picFile.InputStream.Read(image, 0, picFile.ContentLength);
        joinHolder.photo = image;

        byte[] signature = new byte[sigFile.ContentLength];
        sigFile.InputStream.Read(image, 0, sigFile.ContentLength);
        joinHolder.signature = signature;

        joinHolderFactory.Add(joinHolder);
        joinHolderFactory.Save();

        return Json(new { data = "Successfully Saved Data", success = true });

    }
    catch (Exception ex)
    {
        return Json(new { data = ex.Message, success = false });
    }
}

这里有什么问题?
如果我尝试上传单个图像,它正在工作。

4

1 回答 1

0

在 7.2.0 版本之前,您无法将地图指定为file选项,因此您必须这样做

Upload.upload(
          {
              url: '/InvestorManagement/JoinHolder/SaveNewJoinHolder',
              method: 'POST',
              fields: $scope.newJoinHolder,
              file: [picFile, sigFile],
              fileFormDataName: ['picfile', 'sigFile'],

          })

但从 7.2.0 版开始,您的原始代码应该可以工作。您可以验证浏览器的网络选项卡,以确保文件表单数据正在发送到服务器。

于 2015-09-12T17:07:54.400 回答