如何使用二维数组填充列表集合(项目:年份)中的项目?列表集合由使用 linq 查询的外部数据库填充。
视图模型
public class TableViewModel
{
public List<MovieViewModel> Movies { get; set; }
public MyViewModel[,] MovieValues { get; set; }
}
public class MyViewModel
{
public string MovieValue { get; set; }
}
public class MovieViewModel
{
public string Id { get; set; }
public string Name { get; set; }
public string Year { get; set; }
}
控制器
TableViewModel item;
item=new TableViewModel();
var AllMuvees = from d in db.MoviesTable
orderby d.Id
group d by d.Rating into M
select M;
List<MovieViewModel> OldMovies;
foreach (var a in M.AllMuvees)
{
OldMovies.Add(new MovieViewModel()
{
Id = g.MovieId.ToString(),
Name =g.MovieName,
Year = g.MovieYear.ToString()
});
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
item.MovieValues[i, j] = new MyViewModel()
{ MovieValues = *****
(I need help here: I want to fill this with the Years from OldMovies)};
}
}
return View(item);