0

ビューに 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
{
4

1 に答える 1

1

ビューに静的クラスの名前空間を含める必要があります。

@using RandomProject.Helpers;

1 つの提案として、静的クラスを作成する代わりに、viewmodel にプロパティを作成できます。

public class yourViewModel
{
      public IEnumerable<Quantity> Selections {get;set;}
}
于 2013-03-18T08:24:10.603 に答える