我有我的控制器MVC3在where子句
var workshop = registerDB.Workshops.Single(w => w.WorkshopID == id);
ViewBag.Enrollments = registerDB.Carts.Where(x => x.Username.Equals(User.Identity.Name));
以下多個條件,這在我看來
@{
//var carts = Model.Carts.Where(x => x.Username.Equals(User.Identity.Name));
var carts = ViewBag.Enrollments;
var timeSlot = Model.TimeSlot;
}
@{
foreach (var item in carts)
{
if (item != null)
{
if (timeSlot == item.Workshop.TimeSlot)
{
<h3>@timeSlot</h3>
}
}
else
{
<h3>Does not Exist</h3>
}
}
}
每次ViewBag.Enrollments = registerDB.Carts.Where(x => x.Username.Equals(User.Identity.Name));
回報沒有結果,我得到一個錯誤說System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
這行突出顯示
if (timeSlot == item.Workshop.TimeSlot)
我如何檢查ViewBag.Enrollments在用戶沒有做出任何選擇的情況下? –