I am trying to pass some list to my view through ViewModel. I have rebuilt my project several times to no avail. I have checked online, nothing different from my approach.

namespace sportingbiz.Models.ViewModels
{
public class MatchesViewModel
{
private List<MatchViewModel> _matches = new List<MatchViewModel>();
public List<MatchViewModel> Matches
{
get { return _matches; }
set { _matches = value; }
}
}
}
Markup
@model IEnumerable<sportingbiz.Models.ViewModels.MatchesViewModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<table style="width:100%">
@foreach (var item in Model.Matches)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Team1Name)
</td>
</tr>
}
If I remove the .Matches from the foreach it works.Matches does not show in the intellisense.
Your model is
IEnumerable<sportingbiz.Models.ViewModels.MatchesViewModel>which is a series of MatchesViewModels. You need to enumerate that list first before you can callMatches. If you’re only returning one MatchesViewModel, change your model declaration to:Edit – A trick I use often is to hover over any of the instances of
Modeland VS will tell you what type the model is.