0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

Why are you casting to List<WikiModel>?
yeah creating problem related to casting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.