我的问题是这个问题的一部分:
我从一个表单中收到了一组ID。我需要获取这些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);
}
listofIDs
是一个未被执行的IQueryable<string>
,那么就会发生这种情况。在进行转换之前,请先使用ToList()
执行它:listofIDs.ToList().Select(int.Parse).ToList()
。@markthewizard1234 - Michael Hornfeck