簡體   English   中英

ASP.NET C#System.Linq.Enumerable + WhereSelectEnumerable錯誤

[英]ASP.NET C# System.Linq.Enumerable+WhereSelectEnumerable Error

得到這個奇怪的LINQ錯誤。

標題= System.Linq.Enumerable + WhereSelectEnumerableIterator`2 [System.Xml.Linq.XElement,System.String

這是我的代碼:

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;
            } 
        }

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>

試圖使其正確輸出。

代替

title = xml.Descendants(ns + "title").Select (x => x.Value)

改成

title = item.Value

按照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);
}

我在想這個:

var titles = from item in xml.Root.Descendants(ns + "title")                               
             select new{                                   
                title = xml.Descendants(ns + "title").Select (x => x.Value)}; 

應該:

var titles = from item in xml.Root.Descendants(ns + "title")                               
             select item.Value);

快速摘要

..例如,在cshtml剃須刀頁面中使用mvc網格時。

..

 .RenderValueAs(
       item => @Html.ActionLink(
        (
         from tsrItem in (item.<yourColumnName>) 
         where tsrItem.<IdField> == item.<IdField> 
         select tsrItem.<desiredColumn>
        ).FirstOrDefault(),

.. 希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM