2013-03-14 2 views
0

FitToPlay라는 속성이 있으며 부상 당하지 않은 플레이어 목록이 있습니다. 내가하고 싶은 일은 팀 내의 각 포지션을위한 드롭 다운 박스를 만들고 해당 포지션을 1 차 또는 2 차 포지션으로 가지고있는 플레이리스트에있는 플레이어들과 드롭 다운 박스를 채우는 것입니다.MVC 개체에 특정 속성 값이있는 경우 드롭 다운 상자 표시

내가 알고 싶은 것은 어떻게 html 드롭 다운 상자 도우미를 사용하여 특정 개체를 표시 할 수 있습니까?

미리 감사드립니다.

J는

답변

0

난 당신이 모든 현재 FitToPlay 플레이어를 통해 경우 이동 각각의 위치를 ​​통해 루프를 원하는 루프 내부 것이라고 생각하거나 자신의 첫 번째 또는 보조 위치는 현재 다음에 그를 삽입 위치를 통해 반복된다. . 결국 누군가가 .. 뭔가 같은

드롭 다운리스트를 만들 삽입 된 경우

//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); 
    } 
}