我有一个名为product的集合,它有两个字段Id和Name。
创建下拉列表我正在使用
ViewData["Geography"] = new SelectList( parent,"Id","Id");
我想在下拉列表中显示Id + Name。
我尝试了一些不起作用的东西
ViewData["Geography"] = new SelectList( parentCollection,"Id","Id Name");
ViewData["Geography"] = new SelectList( parentCollection,"Id","Id" + "Name");
答案 0 :(得分:0)
从parentCollection
查询并使用select new
ViewData["Geography"] =
new SelectList((from s in parentCollection select new {
ID = s.Id,
IdAndName = s.Id + " " + s.Name}),
"ID",
"IdAndName",
null);