[英]ASP.NET C# System.Linq.Enumerable+WhereSelectEnumerable Error
Getting this weird LINQ error. 得到这个奇怪的LINQ错误。
title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String 标题= System.Linq.Enumerable + WhereSelectEnumerableIterator`2 [System.Xml.Linq.XElement,System.String
Here is the code I have: 这是我的代码:
if (Request.QueryString["Keywords"] != null){
string keywords = Request.QueryString["Keywords"];
string myAppID = "HIDDEN";
var xml = XDocument.Load("http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=" + myAppID + "&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=" + keywords + "&paginationInput.entriesPerPage=5");
XNamespace ns = "http://www.ebay.com/marketplace/search/v1/services";
var titles = from item in xml.Root.Descendants(ns + "title")
select new{
title = xml.Descendants(ns + "title").Select (x => x.Value),
};
foreach (var item in titles){
Label1.Text += item;
}
}
Here what the XML looks like: XML如下所示:
<findItemsByKeywordsResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<searchReslut count="5">
<item>
<title></title>
</item>
<item>
<title></title>
</item>
<item>
<title></title>
</item>
Trying to get it to output correctly. 试图使其正确输出。
Instead of 代替
title = xml.Descendants(ns + "title").Select (x => x.Value)
change to 改成
title = item.Value
EDIT as ChrisGessler suggests, but with my suggestion: 按照ChrisGessler的建议进行编辑,但我的建议是:
if (Request.QueryString["Keywords"] != null)
{
string keywords = Request.QueryString["Keywords"];
string myAppID = "HIDDEN";
var xml = XDocument.Load(/* snip */);
XNamespace ns = "http://www.ebay.com/marketplace/search/v1/services";
var titles = xml.Root.Descendants(ns + "title").Select(x => x.Value);
Label1.Text = String.Join(null, titles);
}
I'm thinking this: 我在想这个:
var titles = from item in xml.Root.Descendants(ns + "title")
select new{
title = xml.Descendants(ns + "title").Select (x => x.Value)};
Should be: 应该:
var titles = from item in xml.Root.Descendants(ns + "title")
select item.Value);
quick snippet 快速摘要
.. as example when using mvc grid in a cshtml razor page.. ..例如,在cshtml剃须刀页面中使用mvc网格时。
.. ..
.RenderValueAs(
item => @Html.ActionLink(
(
from tsrItem in (item.<yourColumnName>)
where tsrItem.<IdField> == item.<IdField>
select tsrItem.<desiredColumn>
).FirstOrDefault(),
.. hope it helps .. 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.