【发布时间】:2017-08-18 13:28:18
【问题描述】:
我正在尝试将 ling 的结果转换为 sql 选择结果到字典。
什么时候做:
var dict = new Dictionary<string, string>();
var encodedContent = new FormUrlEncodedContent(dict);
id 可以毫无问题地接受字典。
当我这样做时:
var dict = leads
.Select((s, i) => new { s, i })
.ToDictionary(x => x.i, x => x.s)
.GetEnumerator();
var encodedContent = new FormUrlEncodedContent(dict);
我收到此错误:
严重性代码描述项目文件行抑制状态 错误 CS1503 参数 1:无法从
System.Collections.Generic.Dictionary<int,PostLeadsToClient.Models.EducatorLead>.Enumerator到System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>PostLeadsToClient C:\RGI Projects\PostLeadsToClient\PostLeadsToClient\Program.cs 159 活动
我一生都无法弄清楚我做错了什么。
我把查询的结果转换错了吗?
【问题讨论】:
-
不要打电话给
GetEnumerator。 -
另外,如果
FormUrlEncodedContent采用Dictionary<string, string>,您需要在索引和EducatorLead对象上调用ToString(或以某种方式将它们转换为string)
标签: c# asp.net-mvc http-post