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 を表示できません。
あなたの助けと時間をありがとう