问题是:我想运行 3 个不同的动作,但我想在更大的模型中从单个动作中提供所有数据。
我在用:
public class SearchScrapClass
{
public WClass WClass { get; set; }
public SClass SClass { get; set; }
public YClass YClass { get; set; }
}
public class WClass
{
public string title { get; set; }
public string link { get; set; }
}
public class SClass
{
public string title { get; set; }
public string link { get; set; }
}
public class YClass
{
public string title { get; set; }
public string link { get; set; }
}
我正在使用 LINQ 在这些模型中添加数据。
我在用 :
var wikians = from info in document.DocumentNode.SelectNodes("//div[@id='span']")
from link in info.SelectNodes("div//a").Where(x => x.Attributes.Contains("href"))
select new SearchScrapClass //Main Bigger Class
{
WClass.link= link.Attributes["href"].Value, //ERROR: How to add to WClass's url ?
WClass.title= link.InnerText //ERROR: How to add to WClass's 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"))
select new SearchScrapClass //Main Bigger Class
{
YClass.link= link.Attributes["href"].Value, //ERROR: How to add to YClass's url ?
YClass.title= link.InnerText //ERROR: How to add to YClass's url ?
}
//Also for the 3rd class (model)
return View(wikians); //and then return bigger class model so that i can access them in view
这是我想将数据添加到所有类的链接和标题的一种方式。
我的尝试是将数据添加到来自不同来源的所有 3 个类,并将更大的模型传递给查看,以便我可以访问所有类:
@model SearchScrapClass
@using(Html.BeginForm()) {
@Html.EditorFor(o => o.WClass.link)
...
}
请建议一种方法
谢谢