ビューに表示するために、コントローラーに selectList を作成します。
私はそれを即座に作成しようとしています、こんな感じのものです...
myViewData.PageOptionsDropDown =
new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15");
コンパイルはできたのですが、出力がおかしいです...
<select id="PageOptionsDropDown" name="PageOptionsDropDown">
<option>10</option>
<option>15</option>
<option>25</option>
<option>50</option>
<option>100</option>
<option>1000</option>
</select>
項目が選択されていないことにお気づきですか?
これをどうすれば修正できますか?
ベストアンサー1
これが私のやり方です
IList<Customer> customers = repository.GetAll<Customer>();
IEnumerable<SelectListItem> selectList =
from c in customers
select new SelectListItem
{
Selected = (c.CustomerID == invoice.CustomerID),
Text = c.Name,
Value = c.CustomerID.ToString()
};
もう一度見ると、あなたが何を求めているのかよく分かりません...