views:

243

answers:

3

Hello

I have 2 for loops and need to check if the model contains value based on current ones.

<% for (int currentDay = 1; currentDay <= 7; currentDay++)
       {  %>
        <%=Html.CheckBox("TimeRange" + currentDay.ToString())%>
    <%} %>

Somehow I need to make the checkbox checked if the model contains data based on 2 parameters (i just put the first loop there)

Kida like:

<%= Html.CheckBox("TimeRange..", (bool)Model.Timetable.Contains(x => x.Time == timeval && x => x.DayOfWeek = i))%>

How is that done?

/M

+3  A: 

I any you want Any rather than Contains, and your syntax is a bit off. Try this:

Model.Timetable.Any(x => x.Time == timeval && x.DayOfWeek == i)

Note that it's just one lambda expression, so there's only one x => bit, and also note the == instead of = in the second condition.

Jon Skeet
A: 

You could try this, not familiar with your data though..

Model.Timetable.Any(x => x.Time == timeval && x.DayOfWeek == i)
Quintin Robinson
A: 
Model.Timetable.ToList().Any ...

Else it will try to execute that on SQL and will likely fail.

leppie