I have a drop-down menu that displays different tabs on the same cshtml page.
- Each tab displays a list of basketball players.
- Issue: all tabs are displaying the same list. (The age group 7and8). The 9-10 tab and 11-12 tab should contain their own list.
- using: bootstrap for the dropdown tabs and mvc-3
The drop down tab:
<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 partial:
@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>
}
}
What I tried:
tested to make sure if the tabs were displaying different information: I added the age group numbers for each tab
7-8 //how I know each tab is different
@{
<div>
<partial name="_Displayeach"/>
</div>
}
where I believe my issue may be:
since each tab was different this leads me to believe it may have something to do with my controller and how I pass the list back. I'm fairly new to mvc framework
[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; }
}
My league model:
int LeagueId { get; set; }
string sport { get; set; }
string gender { get; set; }
string ageRange { get; set; }
List<MMLeagueParticipant> allParticipants { get; set; }
My ViewModel model:
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; }
}
My MMLeagueParticipant middle table for the league model and ViewModel.Participant:
int MMLeaugeParticipantId { get; set; }
int ParticipantId { get; set; }
int LeaugeId { get; set; }
leauge sport { get; set; }
ViewModel.Participant child { get; set; }