FitToPlay というプロパティがあり、負傷していないプレーヤーのリストが含まれています。私がやりたいことは、チーム内の各ポジションのドロップダウン ボックスを作成し、そのドロップダウン ボックスに、問題のポジションをプライマリまたはセカンダリ ポジションとして持っている、プレイに適したリストのプレーヤーのみを入力することです。
私が知りたいのは、html ドロップダウン ボックス ヘルパーを使用して特定のオブジェクトを表示する方法です。
よろしくお願いします。
J
FitToPlay というプロパティがあり、負傷していないプレーヤーのリストが含まれています。私がやりたいことは、チーム内の各ポジションのドロップダウン ボックスを作成し、そのドロップダウン ボックスに、問題のポジションをプライマリまたはセカンダリ ポジションとして持っている、プレイに適したリストのプレーヤーのみを入力することです。
私が知りたいのは、html ドロップダウン ボックス ヘルパーを使用して特定のオブジェクトを表示する方法です。
よろしくお願いします。
J
各ポジションをループし、ループ内で現在のすべての FitToPlay プレーヤーを通過し、最初または 2 番目のポジションのいずれかが現在ループされているポジションである場合は、そのポジションに挿入したいと思います。最後に誰かが挿入された場合は作成しますドロップダウンリスト
だから何か..
//Loop through all the positions
foreach (var position in Model.positions)
{
//Create a list for each position
List<SelectListItem> playersInPosition = new List<SelectListItem>();
//Only loop through players with the current position as either primary or secondary
foreach(var player in Model.FitToPlay.Where(pl => pl.primary == position || pl.secondary == position))
{
//Put this player into the list
playersInPosition.add(new SelectListItem { Text = player.name, Value = player.id});
}
//If at least one fits the criteria make a drop down list from it
if(playersInPosition != null && playersInPosition.Count > 0)
{
@Html.DropDownList(position.name, playersInPosition);
}
}