Passing array of objects int jQuery .data() attributeto list<t>

时间:2015-06-15 15:01:48

标签: javascript jquery asp.net json

I have a array of objects that are of a type ProductField. I am passing it using JQuery to a WebMethod that is setup to accept the data.

The call is made as below:

data: JSON.stringify({ProductNumber: ProductInfo.ProductNumber, ProductFieldList: ProductInfo.ProductFieldList.ProductFields, IsPreSelected: ispreselected }),

and the web method is below:

[WebMethod]

public static object AddCandidateSolution(string ProductNumber, List<ProductField> ProductFieldList, bool IsPreSelected)

if you use fiddler you can see that the data is being sent over

{
  "ProductNumber": "INS_00005",
  "ProductFieldList": [
    {
      "__type": "Datastructure.BaseClasses.ProductField",
      "ProductFieldID": 1,
      "ProductTypeID": 4,
      "Name": "State",
      "Prompt": "Drivers License State:",
      "DataTypeID": 5,
      "Required": true,
      "MinLength": 2,
      "MaxLength": 2,
      "Validation": "fn_isValidState(1)",
      "Visible": true,
      "Value": "NC",
      "DefaultValue": ""
    },
    {
      "__type": "Datastructure.BaseClasses.ProductField",
      "ProductFieldID": 3,
      "ProductTypeID": 4,
      "Name": "License",
      "Prompt": "Drivers License Number:",
      "DataTypeID": 3,
      "Required": true,
      "MinLength": 0,
      "MaxLength": 0,
      "Validation": "Utility.ufn_Validate_DriversLicenseFormat(1,3)",
      "Visible": true,
      "Value": "9951847",
      "DefaultValue": ""
    },
    {
      "__type": "Datastructure.BaseClasses.ProductField",
      "ProductFieldID": 4,
      "ProductTypeID": 4,
      "Name": "Term",
      "Prompt": "Drivers License Term:",
      "DataTypeID": 5,
      "Required": true,
      "MinLength": 1,
      "MaxLength": 1,
      "Validation": "fn_isValidDriversTerm(1,4)",
      "Visible": true,
      "Value": "3Y",
      "DefaultValue": ""
    }
  ],
  "IsPreSelected": "false"
}

However my issue is that when I am in the WebMethod, the values for ProductNumber and IsPreSelected are being set, but the List is set to a size of 3 but the data is not being filled in.

Any suggestions??

1 个答案:

答案 0 :(得分:0)

我得到了它的工作。我的班上有{得到;私人套装}。一旦我删除私有集并替换为set,它就可以正常工作。