2009-10-30 83 views

回答

0

我想,你需要创建一个viewdata,或者创建一个viewmodel来将选择列表传递给下拉列表。例如,在你的控制器动作,你应该做的某事像这样:

//get your item for editing here i.e named itemToEdit 
    //get your country collection here 

     ArrayList countryList=New ArrayList; 
     foreach (Country c In YourCountryCollection) 
{   countryList.Add(New With {.Item = c.CountryName, .value = c.CountryID}) 
} 
    Viewdata("CountryList")=New SelectList(countryList, "Value", "Item", itemToEdit.countryID)} 

现在,在你看来,而不是使用html.editorfor,你应该uuse如下: Html.Editor(“CountryLis”,“ CountryDropDown“)

这应该使用所选值设置您的下拉列表。 希望得到这个帮助。