Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using a action called scrap as

public ActionResult Scrap()
 {
    var webGet = new HtmlWeb();
    var document = webGet.Load(Url);
    var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='results']")
                  from link in info.SelectNodes("p//a").Where(x => x.Attributes.Contains("href"))
                  from content in info.SelectNodes("p").Where(y => y.HasAttributes != true)
                  select new
                    {
                      LinkURL = link.Attributes["href"].Value,
                      Text = content.InnerText                             
                    };

 return View();
}

Now I want to show all LinkURL and Text in view. For that I tried to use a model called WikiModel as

public class WikiModel
{
  public string url { get; set; }
  public string content { get; set; }
}

Now how can I go further so that I can show all infomation in my view. We can do so using the wikimodel but how to add all scrap action's data in this wikimodel? I don't know how to manipulate his select new of LINQ to save data in model.

share|improve this question

2 Answers

up vote 2 down vote accepted

To start with, you need to return list of your WikiModel objects from your query:

 var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='results']")
                  from link in info.SelectNodes("p//a").Where(x => x.Attributes.Contains("href"))
                  from content in info.SelectNodes("p").Where(y => y.HasAttributes != true)
                  select new WikiModel
                    {
                      url = link.Attributes["href"].Value,
                      content = content.InnerText                             
                    };

You can pass this through to the view as the Model:

return View(wikians);

In your view, you now have access to this list via the Model.

share|improve this answer
thanks i worked... – Man8Blue May 28 '12 at 19:19
public ActionResult Scrap()
 {
    var webGet = new HtmlWeb();
    var document = webGet.Load(Url);
    var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='results']")
                  from link in info.SelectNodes("p//a").Where(x => x.Attributes.Contains("href"))
                  from content in info.SelectNodes("p").Where(y => y.HasAttributes != true)
                  select new WikiModel

                    {
                      LinkURL = link.Attributes["href"].Value,
                      Text = content.InnerText                             
                    };

 return View(wikians);
}
share|improve this answer
Why are you casting to List<WikiModel>? – Oded May 28 '12 at 17:45
yeah creating problem related to casting – Man8Blue May 28 '12 at 19:20
ok thanks, @Oded I have removed the casting. – KPL May 29 '12 at 3:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.