将ko.mapping.toJSON数据传递给WCF会导致null变量

时间:2013-03-11 17:33:18

标签: json wcf knockout.js

将这样的字符串传递给WCF服务是否可以:

self.savePreferences = function(callback) {
        $.ajax({
            url: "services/Foo.svc/SavePreferences",
            type: 'POST',
            timeout: 3000,
            data: ko.mapping.toJSON(self.user().preferences),
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                if (result) {
                    alert("data saved " + result);
                } else {
                    //todo, send server email alert
                    alert("Something went wrong. We will look into it.");
                }
            }
        });
    }

在这种情况下,我的服务中的jsonPreferences总是为null

 [OperationContract]
    [WebInvoke(
      Method = "POST", 
      RequestFormat = WebMessageFormat.Json)]
    string SavePreferences(string jsonPreferences);

或者我需要这样做:

data:JSON.stringify(ko.mapping.toJSON(self.user()。preferences))

0 个答案:

没有答案