ビューに 1,2,3,4,5 などDropDownListFor
の が必要です。DropDownlist
私のモデルクラスでは:
public class PageModel
{
[DisplayName("Quantity")]
public int Quantity { get; set; }
}
Quantity
クラスを作成しました
public class Quantity
{
public int Selection { get; set; }
}
HtmlList クラス
public static class HtmlLists
{
public static IEnumerable<Quantity> Selections = new List<Quantity> {
new Quantity {
Selection = 1
},
new Quantity {
Selection = 2
}
};
私の見解では:
@Html.LabelFor(m => m.Quantity):
<td>@Html.DropDownListFor(m => m.Quantity, new SelectList(HtmlList.Selections, "Selection"))
それは私にエラーを与えていますHtmlList.Selections
:
名前 'HtmlList' は現在のコンテキストに存在しません
編集:
エラーの問題は @using YourNameSpaceofStaticClass で修正されました
しかし今、私は次の問題を抱えています:
ドロップダウンリストで選択1と2を表示する代わりに、彼は私に表示しています:
ModelNamespace.Quantity ModelNamespace.Quantity
これは、リストが空であるためだと思います..
私の Quantity クラスの名前空間:
namespace ModelNamespace
{