0

我的視圖模型如下:綁定一個簡單的整數數組到一個DropDownList在MVC3

public class ClassificationCalculatorIndexViewModel 
{ 
    public bool PlacementYear { get; set; } 
    public int[] Credit { get; set; } // List of Integers 
    public int selectedCredit { get; set; } // Somewhere to store selected integer 
    public List<YearOfStudy> StudyYear { get; set; } 
} 

我奮力的整型數組來一個DropDownList輔助對象綁定在我的Razor視圖,我做了以下內容:

@Html.DropDownListFor(Model.selectedCredit, Model.Credit) 

但是,得到的錯誤,我想谷歌搜索,但一無所獲同一性質:(

+0

什麼是錯誤您收到? – Dismissile

+0

方法DropDownListFor <>的類型參數不能從使用推斷,請嘗試明確指定類型參數 – Ciwan

回答

4

我認爲你需要降下來selectedCredit裝滿物品從Credit屬性:

@Html.DropDownListFor(m => m.selectedCredit, new SelectList(Model.Credit)) 
+1

這樣做,謝謝你LazyBerezovsky :) – Ciwan

0

你需要創建一個SelectList對象與你內容。

+0

感謝Romias,但是如何? – Ciwan