我只是在学习MVC。这是我到目前为止所尝试的:
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();
}
在视图中:
@Html.DropDownList("store", ViewBag.Stores as SelectList, "Select a Store")
我在这里做错了什么?下拉列表仅显示 Cie_Mvc.Models.StoreXml,但不显示值。请建议。