我只是在學習MVC。這是我迄今爲止嘗試:列表沒有顯示在DropDown菜單在查看
public class StoreXml
{
public string StoreCode { get; set; }
public static IQueryable<StoreXml> GetStores()
{
return new List<StoreXml>
{
new StoreXml { StoreCode = "0991"},
new StoreXml { StoreCode = "0015"},
new StoreXml { StoreCode = "0018"}
}.AsQueryable();
}
在控制器:
public SelectList GetStoreSelectList()
{
var Store = StoreXml.GetStores();
return new SelectList(Store.ToArray(),"StoreCode");
}
public ActionResult IndexDDL()
{
ViewBag.Store = GetStoreSelectList();
return View();
}
在View:
@Html.DropDownList("store", ViewBag.Stores as SelectList, "Select a Store")
什麼我錯在這裏做什麼?下拉菜單僅顯示Cie_Mvc.Models.StoreXml,但沒有值。請建議。
謝謝加布,我用ViewBag.Stores這兩種情況。還是一樣的。 – prasuangelo 2013-05-03 14:06:25