小编典典

如何转换清单 列出?

c#

我的问题是这个问题的一部分:

我从表单中收到ID的集合。我需要获取键,将它们转换为整数,然后从数据库中选择匹配的记录。

[HttpPost]
public ActionResult Report(FormCollection collection)
{
    var listofIDs = collection.AllKeys.ToList();  
    // List<string> to List<int>
    List<Dinner> dinners = new List<Dinner>();
    dinners= repository.GetDinners(listofIDs);
    return View(dinners);
}

阅读 190

收藏
2020-05-19

共1个答案

小编典典

listofIDs.Select(int.Parse).ToList()
2020-05-19