整數的名單我有這樣的代碼:遍歷從數據庫
public ActionResult DeleteBehandling(int id)
{
AppointmentDiary _ad = new AppointmentDiary();
var beh = _db.Behandlingar.Single(k => k.BehandlingarId == id);
foreach (var item in _ad.BehandlingarId)
{
if (_ad.BehandlingarId == id)
{
return View();
}
}
_db.Behandlingar.Remove(beh);
_db.SaveChanges();
return RedirectToAction("BehandlingarNy");
}
_ad.BehandlingarId
是含int
我的數據庫中的列。現在,我想遍歷這一列,看看我是否與輸入匹配。我得到這個錯誤:
foreach statement cannot operate on variables of type 'int' because 'int' does not contain a public definition for 'GetEnumerator.
如何突破這個?
謝謝!
什麼'BehandlingarId'的確切數據類型? – Yasser
錯誤消息說明了這一切...你正試圖對一些不是集合的東西進行foreach,而是一個'int'! –
好的!有沒有一種方法可以將我的列中的整數轉換爲我可以循環使用的集合? – user2915962