Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.88 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to show LINQ data in view in asp.net mvc?
  2. public ActionResult Scrap()
  3.  {
  4.     var webGet = new HtmlWeb();
  5.     var document = webGet.Load(Url);
  6.     var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='results']")
  7.                   from link in info.SelectNodes("p//a").Where(x => x.Attributes.Contains("href"))
  8.                   from content in info.SelectNodes("p").Where(y => y.HasAttributes != true)
  9.                   select new
  10.                     {
  11.                       LinkURL = link.Attributes["href"].Value,
  12.                       Text = content.InnerText                            
  13.                     };
  14.  
  15.  return View();
  16. }
  17.        
  18. public class WikiModel
  19. {
  20.   public string url { get; set; }
  21.   public string content { get; set; }
  22. }
  23.        
  24. var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='results']")
  25.                   from link in info.SelectNodes("p//a").Where(x => x.Attributes.Contains("href"))
  26.                   from content in info.SelectNodes("p").Where(y => y.HasAttributes != true)
  27.                   select new WikiModel
  28.                     {
  29.                       url = link.Attributes["href"].Value,
  30.                       content = content.InnerText                            
  31.                     };
  32.        
  33. return View(wikians);
  34.        
  35. public ActionResult Scrap()
  36.  {
  37.     var webGet = new HtmlWeb();
  38.     var document = webGet.Load(Url);
  39.     var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='results']")
  40.                   from link in info.SelectNodes("p//a").Where(x => x.Attributes.Contains("href"))
  41.                   from content in info.SelectNodes("p").Where(y => y.HasAttributes != true)
  42.                   select new WikiModel
  43.  
  44.                     {
  45.                       LinkURL = link.Attributes["href"].Value,
  46.                       Text = content.InnerText                            
  47.                     };
  48.  
  49.  return View(wikians);
  50. }