我有一个名为 Fixture 的实体,基本上我想在页面上显示一些灯具。
我的模型如下:-
public class Fixture
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int FixtureId { get; set; }
[Display(Name = "Fixture Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? FixtureDate { get; set; }
public DateTime? FixtureTime { get; set; }
public int? CityId { get; set; }
public City City { get; set; }
public int CountryIdA { get; set; }
public int CountryIdB { get; set; }
public int? ScoreA { get; set; }
public int? ScoreB { get; set; }
public Round Round { get; set; }
public int? RoundId { get; set; }
public List<Scorer> Scorers { get; set; }
}
我的 ViewModel 如下:-
public class FixtureViewModel
{
public Fixture Fixture { get; set; }
public IEnumerable<Fixture> FixtureList { get; set; }
public IEnumerable<GroupCountry> GroupCountryList { get; set; }
public IEnumerable<Group> GroupList { get; set; }
public string CountryNameA { get; set; }
public string CountryNameB { get; set; }
}
我在这个索引页面中显示它们:-
<table>
<tr>
<th>
@Html.DisplayName("Date")
</th>
<th>
@Html.DisplayName("Country A")
</th>
<th>
@Html.DisplayName("Country A")
</th>
<th>
@Html.DisplayName("Score A")
</th>
<th>
@Html.DisplayName("Score B")
</th>
<th>
@Html.DisplayName("Round")
</th>
<th></th>
</tr>
@foreach (Fixture item in Model.FixtureList)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.FixtureDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.CountryIdA)
</td>
<td>
@Html.DisplayFor(modelItem => item.CountryIdB)
</td>
<td>
@Html.DisplayFor(modelItem => item.ScoreA)
</td>
<td>
@Html.DisplayFor(modelItem => item.ScoreB)
</td>
<td>
@Html.DisplayFor(modelItem => item.Round.RoundName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new {id = item.FixtureId}) |
@Html.ActionLink("Details", "Details", new {id = item.FixtureId}) |
@Html.ActionLink("Delete", "Delete", new {id = item.FixtureId})
</td>
</tr>
}
</table>
现在在索引页面中,我希望显示如下内容:-
<td>
@Html.DisplayFor(modelItem => item.CountryIdA.Country.CountryName)
</td>
<td>
@Html.DisplayFor(modelItem => item.CountryIdB.Country.CountryName)
</td>
我怎样才能做到这一点?
我在模型中添加了一个导航项 Country,但是我仍然无法显示正确的 CountryName。
感谢您的帮助和时间