【发布时间】:2021-08-26 00:10:39
【问题描述】:
我有一个下拉菜单,在同一个 cshtml 页面上显示不同的选项卡。
- 每个选项卡都显示一个篮球运动员列表。
- 问题:所有选项卡都显示相同的列表。 (年龄组 7 和 8)。 9-10 选项卡和 11-12 选项卡应包含各自的列表。
- 使用:下拉选项卡和 mvc-3 的引导程序
下拉选项卡:
<div class="col-9">
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-pills-boy" role="tabpanel" aria-labelledby="v-pills-boy-tab">
<nav>
<ul class="nav nav-tabs nav-justified" id="nav-tab" role="tablist">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">b-Age</a>
<li class="dropdown-menu">
<a class="dropdown-item nav-link" id="bbM7and8-tab" data-toggle="tab" href="#bbM7and8" role="tab" aria-controls="bbM7and8" aria-selected="false">7-8</a>
<a class="dropdown-item nav-link" id="bbM9and10-tab" data-toggle="tab" href="#bbM9and10" role="tab" aria-controls="bbM9and10" aria-selected="false">9-10</a>
<a class="dropdown-item nav-link" id="bbM11and12-tab" data-toggle="tab" href="#bbM11and12" role="tab" aria-controls="bbM11and12" aria-selected="false">11-12</a>
</li>
</ul>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade" id="bbM7and8" role="tabpanel" aria-labelledby="bbM7and8-tab">
@{
<div>
<partial name="_Displayeach"/>
</div>
}
<div class="tab-pane fade" id="bbM9and10" role="tabpanel" aria-labelledby="bbM9and10-tab">{...}</div>
<div class="tab-pane fade" id="bbM11and12" role="tabpanel" aria-labelledby="bbM11and12-tab">{...}</div>
</div>
</div>
_Displayeach 部分:
@model List<League>
@{
if (Model != null && Model.Any())
{
foreach(League i in Model)
{
foreach (MMLeagueParticipant mmLeagueParticipant in i.allParticipants)
{
<p>@mmLeagueParticipant.child.ParticipantFirstName @mmLeagueParticipant.child.ParticipantLastName</p>
}
}
}
else
{
<p>the list is empty</p>
}
}
我尝试了什么:
测试以确保标签是否显示不同的信息:我为每个标签添加了年龄组编号
7-8 //how I know each tab is different
@{
<div>
<partial name="_Displayeach"/>
</div>
}
我认为我的问题可能在哪里:
由于每个选项卡都不同,这让我相信它可能与我的控制器以及我如何将列表传回有关。我对 mvc 框架还很陌生
[HttpGet]
[Route("roster/basketball")]
public async Task<IActionResult> GetBasketballRoster()
{
String[] leagueNames = new[]
{
"7and8",
"9and10",
"11and12"
};
List<League> bbLeagues = await db.Leagues
.Where( l => l.sport == "Basketball" )
.Where( l => leagueNames.Contains( l.ageRange ) )
.ToListAsync();
foreach( League league in bbLeagues )
{
List<MMLeagueParticipant> leagueParticipants = await db.Entry( league )
.Collection( l => l.allParticipants )
.Query() // <-- This is needed to allow for `Include()`
.Include( mmp => mmp.child )
.ToListAsync();
}
return View("RosterPageBasketball", bbLeagues);
}
public class RosterPageViewModel
{
public RosterPageViewModel(IReadOnlyDictionary< String, League > leagues)
{
this.Leagues = leagues ?? throw new ArgumentNullException(nameof(leagues));
}
public IReadOnlyDictionary< String, League > Leagues { get; }
}
我的联赛模型:
int LeagueId { get; set; }
string sport { get; set; }
string gender { get; set; }
string ageRange { get; set; }
List<MMLeagueParticipant> allParticipants { get; set; }
我的 ViewModel 模型:
public List<Participant> allParticipants { get; set; }
public ViewModel.Participant participant { get; set; }
public class Participant
{
int ParticipantId { get; set; }
string ParticipantFirstName { get; set; }
string ParticipantLastName { get; set; }
string ParticipantGender { get; set; }
SystemDateTime ParticipantDOB { get; set; }
List<MMLeagueParticipant> all Leagues { get; set; }
}
我的 MMLeagueParticipant 中间表用于联赛模型和 ViewModel.Participant:
int MMLeaugeParticipantId { get; set; }
int ParticipantId { get; set; }
int LeaugeId { get; set; }
leauge sport { get; set; }
ViewModel.Participant child { get; set; }
【问题讨论】:
标签: c# asp.net-mvc asp.net-core dynamic tabs