* Razor - ドロップダウンリスト [#x6544369]
** Cotroller [#wa52bc55]
var teamList = _teamService.GetTeamList().ToList();
teamList.Insert(0, new teamEntity()); // 先頭にブランクを追加
playerVm.TeamList = new SelectList(teamList, "team_id", "team_name");
** ViewModel [#l88e4305]
public class PlayerViewModel
{
public IEnumerable<SelectListItem> TeamList { get; set; }
}
** View [#f6e1d989]
@using (Html.BeginForm("PlayerEdit", "Home", null, FormMethod.Post))
{
@Html.HiddenFor(x => x.Player_id)
<table>
<tr>
<th>@Html.LabelFor(x => x.Team_name)</th>
<th>@Html.LabelFor(x => x.Team_id)</th>
<td>@Html.DropDownListFor(x => x.Team_id, Model.TeamList)</td>
</tr>
</table>
<div><input type="submit" value="OK" /></div>
}
** multiple [#e8c70d0a]
http://stackoverflow.com/questions/7839760/how-can-i-create-a-selectlist-with-multiple-selected-values
** 参考 [#b98cac62]
: @IT ASP.NET MVC入門 | http://www.atmarkit.co.jp/fdotnet/aspnetmvc3/aspnetmvc3_06/aspnetmvc3_06_04.html
: MSDN | http://msdn.microsoft.com/ja-jp/library/dd410596(v=vs.100).aspx
: 「ドロップダウンリストを表示する時、Controller側でSelectListとSelectListItemのどちらを使えばよいか」 | http://miso-soup3.hateblo.jp/entry/20111101/1320160294