我一直在努力使用SelectList并决定尝试一个简单的实验:
SelectList list = new SelectList(db.People.OrderBy(x => x.Last), "ID", "Last", sItem);
foreach (SelectListItem item in list)
{
item.Text = item.Text.ToUpper();
}
return list;
当它结束时,检查列表显示项目未经修改。是什么赋予了?显然在这里遗漏了一些东西。
答案 0 :(得分:0)
您可以使用linq投影来创建SelectList项目:
var toupper = db.People.OrderBy(x => x.Last)
.Select(x => new
{
Id = x.Id,
Last = x.Last.ToUpper(), //Whatever you want to upper case
Whatever = x.Whatever
// Add other items you want to show in select list
});
SelectList list = new SelectList(toupper, "Id", "Last", sItem);
return list;