【问题标题】:Passing array of objects int jQuery .data() attributeto list<T>将对象数组 int jQuery .data() 属性传递给 list<T>
【发布时间】:2015-06-15 15:01:47
【问题描述】:

我有一个 ProductField 类型的对象数组。我使用 JQuery 将它传递给设置为接受数据的 WebMethod。

调用如下:

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

web方法如下:

[WebMethod]

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

如果你使用 fiddler,你可以看到数据正在发送过来

{
  "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"
}

但是我的问题是,当我在 WebMethod 中时,正在设置 ProductNumber 和 IsPreSelected 的值,但 List 的大小设置为 3,但没有填写数据。

有什么建议吗??

【问题讨论】:

  • webmethods能否自动绑定json post数据中的参数列表?
  • 以前的开发人员已经在另一个具有不同类的项目中完成了它,但我无法在这个项目中复制它。 is 之后有一个函数,但我不知道它在做什么。
  • 这是之前的工作数据: JSON.stringify({ ProductFieldList: ServiceInfo, IsPreselected: ispreselected }, function (k, v) { return v === "" ? "" : v }),

标签: javascript jquery asp.net json


【解决方案1】:

我让它工作了。我的班级有{get;私人集}。一旦我删除了私有集并替换为集,它就可以正常工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 2014-06-30
    • 2017-02-25
    相关资源
    最近更新 更多