2017-08-07 158 views
0

这是我必须获取认证列表的代码。我还想添加单词“全部”到列表中。我会怎么做?当我在声明结尾尝试+ "ALL"时,它不起作用。将自定义选项添加到查看包列表

ViewBag.CertificationList = (from r in _context.INT_Certifications select r.Certification).Distinct(); 
+0

这是什么意思'它不工作? –

+0

我们帮助你的政府吗? ;) –

+1

是的;)我们很感谢 –

回答

2

你试过类似的东西吗? (未经测试):

var lst = (from r in _context.INT_Certifications select r.Certification).Distinct().ToList(); 
lst.add("all"); 
ViewBag.CertificationList = lst; 
+1

('Distinct().ToList()'* \ *咳嗽**)) – poke

+0

感谢@poke,我编辑它。 – Noren

+0

这对我所需要的非常适合!谢谢! –

2

我还想添加单词 “全部” 列表

我要牵着你的字在这里:)试试这个:

List<string> res = (from r in _context.INT_Certifications select r.Certification).Distinct().ToList(); 
res.Add(" All"); 
ViewBag.CertificationList = res; 

当我在语句结尾处尝试+“ALL”时,它不起作用。

因为你试图连接一stringIEnumerable<string>

IEnumerable<string>不知道+操作。如果你想在一个字符串中枚举的元素,你可以像这样变形:

string allItems = String.Join(" ", ViewBag.CertificationList) + " All"; 
+1

OP的'CertificationList'是一个'IEnumerable',所以它没有'Add'。 – poke

+0

@poke谢谢你的提示 –

+0

非常感谢! –

相关问题