与其试图将2个选择列表连接在一起,为什么不把它们合并在一起?您还没有提供太多的信息,但假设你使用LINQ
和假设你的城市和国家之间的关系分贝...
// get the city & state data
var cities = (from c in GetAllCities()
orderby c.Name
orderby c.State.Name
select new
{
cityid = c.Id,
cityname = c.Name,
state = e.State.Name
}).ToList();
// convert the data into a list of `SelectListItem`
var items = from cs in cities.AsEnumerable()
select new SelectListItem
{
Value = cs.cityid.ToString(),
Text = string.Format("{0} {1} ({2})", cs.cityname, cs.state)
};
// create the selectlist
return new SelectList(items , "Value", "Text");