$http放入angularjs到webapi调用,将对象一属性作为null传递

z3yyvxxp  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(241)

我对angularjs是新手。我创建了一个对话框来更新一个类对象。除id属性外,所有其他属性都正确。
类别:

[Serializable]
public class Payment
{
    public virtual string Id { get; set; }

    public virtual string PaymentId{ get; set; }

    public virtual string FeeType { get; set; }

    public virtual string Payer { get; set; }

    public virtual string Receiver { get; set; }

}

angularjs服务

var updatePaymentData = function (payment) {
        return serviceBase
            .put(serviceBase.applicationServiceWebApiUrl + "api/ExportMaintenance/UpdatePayment", payment)
            .then(function (result) {
                loggingManager.logSuccessMessage("payment " + payment.feeType + " has been updated.");

                return result;
            });
    };

servicebase put代码:

function httpRequestWithTimeOut(req, timeOut) {
        var timeOutLength = timeOut;
        var hasTimeOut = false;
        var timeout = $q.defer();
        var deferred = $q.defer();

        setTimeout(function () {
            hasTimeOut = true;
            timeout.resolve();
        }, (1000 * timeOutLength));

        // Add the default timeout promise.
        req.timeout = timeout.promise;

        $http(req)
            .success(function (result) {
                deferred.resolve(result);
            })
            .error(function (error) {
                if (hasTimeOut) {
                    deferred.reject({
                        error: "timeout",
                        message: "The request took too long and has time out."
                    });
                } else {
                    deferred.reject(error);
                }
            });

        return deferred.promise;
    } 

 var put = function (location, data) {
        var req = {
            method: "put",
            url: location,
            data: data,
            cache: false
        };

        return httpRequest(req);
    };
 function httpRequest(req) {
        // Default time out to 180 seconds.
        return httpRequestWithTimeOut(req, 180);
    }

web api相关代码:

// PUT api/ExportMaintenance/UpdatePayment
    [HttpPut, ValidateModel]
    [WebApiClaimsAuthorization(Type = "ExportMaintenance", Value = "CanUpdate", Description = "Can update Export Maintenance")]
    public HttpResponseMessage UpdatePayment(Payment paymentData)
    {
        var responseMessage = new ResponseMessage(Request, paymentData);

        _paymentBusinessLogic.UpdatePaymentData(paymentData, User, responseMessage);

        return responseMessage.SetHttpResponseMessage(paymentData);
    }


数据对象映像输入请求

它们是类中的更多属性,我在写入时删除了它们,所有属性都显示在“网络”选项卡的“数据对象映像请求有效负载”中

在webapi中,我得到payment.id为null,但当我在chrome调试工具中看到paymentdata在控制器和服务中具有id值时。
我不明白为什么id是空的。请至少帮我分析一下这个问题。
谢谢,nagasree。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题