0
我想創建一個下拉列表中的自定義集合類 如在MVC3
public class MyCustomClassCollection
{
public List<MyCustomClass> {get;set;}
}
我想讓它顯示的說明顯示所有創造價值的下拉列表:每個MyCustomClass
串我試圖
<%: Html.DropDownList "Description", MyCustomClass %>
ReSharper的建議我投MyCustomClass到IEnemerable
但服務器返回無法投射錯誤。
任何想法我怎麼能創造這個DropDownList的?
__變形_ __
public class ViewModel
{
public Detail detail { get; set; }
}
public class Detail //Inherited from webservce
{
public CustomClassCollection {get;set;}
.... Other Properties, a.k.a Custom Classes
}
public class CustomClassCollection
{
public List<CustomClass> {get;set;}
}
public class CustomClass {
public int Id {get;set;}
public string Description{get;set;}
... other properties
}
public ActionResult Index(int? id, DateTime? date)
{
if (id.Equals(null))
id = ######### ;
if (date.Equals(null))
date = DateTime.Today;
var vm = new ViewModel
{
Detail = _repository.Detail((int)id,(DateTime)date)
};
return View(vm);
}
這不工作我不能選擇過去的定製集合。然後它開始給我選擇,如選擇,其中... –
@Antarr伯德,這個自定義集合是怎麼樣的?你所顯示的代碼甚至不會編譯。請提供對象層次結構中涉及的對象的完整描述。 –
我會在上面發佈修改後的代碼,通過web服務訪問數據而不是LINQ –