Click here to Skip to main content
15,912,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
[WebMethod]
       [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
       public static List<string> url_nav(int jobid)
       {
           huntableEntities dc = new huntableEntities();
           List<string> urls = new List<string>();
           {


               urls = (from n in dc.Jobs.Where(m => m.Id == jobid)
                       select new { n.Url,n.IsRssJob}).ToList();


           }
           return urls;

       }

please help me how to get n.url and n.IsRssJob column valuse to a variable using jquery and webservice and it showing typecast error tolist how to write the linq query
Posted
Updated 3-Jun-14 6:46am
v2

1 solution

You are selecting two values in your LINQ and applying ToList to List<string> type. This is wrong.
If your return type has to be List<string> then below like only will work.
C#
urls = (from n in dc.Jobs.Where(m =&amp;gt; m.Id == jobid)
 select nn.Url).ToList();

else, you need to have a domain model
class model{string Url;bool IsRssJob;}

Now this is fine
C#
public static List<model> url_nav(int jobid)
       {
           huntableEntities dc = new huntableEntities();
           List<model> urls = new List<model>();
           {


               urls = (from n in dc.Jobs.Where(m => m.Id == jobid)
                       select new model{Url= n.Url,IsRssJob =n.IsRssJob}).ToList();


           }
           return urls;

       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900