【发布时间】:2016-05-11 12:15:56
【问题描述】:
这是我要返回的返回类型Dictionary<ReportID, ReportDatail>
其中类的结构为:
Class ReportDetail
{
ReportID,
ReportName,
ReportShortName,
List<ReportFields>
}
Class ReportFields
{
SystemName,
DBName,
DataType,
MaxLength,
DefaultValue
}
我不知道如何将该响应作为字典返回。
function GetReportsDetails(AccoutType) {
$.ajax({
type: "POST",
url: '<%= ResolveUrl("~/Web/ReportPosition.aspx/GetReportDetail") %>',
contentType: "application/json; charset=utf-8",
datatype: 'json',
data: JSON.stringify({SelectedAccount: AccoutType}),
success: function (data) {
alert(data.d);
},
error: function (xhr, status, error) {
alert('XHR: ' + xhr.responseText + '\nStatus: ' + status + '\nError: ' + error);
}
});
[WebMethod]
public static string GetReportDetail(string AccoutItem)
{
return "Response from WebMethod..!";
//What type of code I've to write here to return "Dictionary<ReportID, ReportDatail>"
}
在上面的网络方法中,我只是返回字符串而不是字典作为响应,但仍然得到错误:
Type \u0027System.String\u0027 is not supported for deserialization of an array.
如何将数据传递给WebMethod 并将响应返回为来自WebMethod 的字典
【问题讨论】:
-
你是这个意思?
return new Dictionary<ReportID, ReportDatail>();?目前还不清楚这里有什么问题。 -
有点困惑。您是否要返回 Dictonary
,但 ReportID 不是类型。实际上,它是 ReportDetail 类的一个属性。我猜你的意思是 Dictionary 其中 T 是 ReportID 类型,不是吗? -
我已经存储了 Dictionary Result 并希望返回 Dictionary
其中键值作为 ReportDetails 的 ReportID.. -
@David,是的,我想返回 Dictionary
作为键 ReportID表示 Dictionary 中与之关联的 ReportType..! -
@Kaishu:好的。我想问题是......是什么阻止了你?
标签: jquery asp.net ajax webmethod