开发者

If IQueryable contains in model?

开发者 https://www.devze.com 2022-12-11 13:30 出处:网络
I have this loop that renders a schedule with checkboxes for each entry like this: MondayTuesday..... 08:00-09:00[ ][ ]...

I have this loop that renders a schedule with checkboxes for each entry like this:

              Monday    Tuesday.....
08:00-09:00     [ ]        [ ]...
10:00-11:00     [ ]        [ ]...

Using this code in my view:

    <% for (int i = 1; i < 10; i++)
   {%>
<tr>
    <td>
        xx:00 - xx:00
    </td>
    <% for (int currentDay = 1; currentDay <= 7; currentDay++)
       {  %>
    <td>
        <%=Html.CheckBox("TimeRange" + currentDay.ToString()) %>
    </td>
    <%} %>
</tr>
<% } %>

Now I need to check if, for example, 08:00 Tuesday exists in Model.Timetable, i.e DayOfWeek = 2 And StartTime = '08:00'.

开发者_开发百科

So I need:

1) Check if current value exists in Model.Timetable 2) Set it to checked in that case 3) Set the value of the checkbox to Model.Timetable.StartTime

How is that done?

/M


there is a way in jQuery to set a check box to checked based on the value of the checkbox.

$(".schedule[value='01012009']").attr("checked", "checked");

.schedule is the class that you have assigned to the check box and the value needs to be unique. .schedule class doesn't need to exist in the style sheet. It's an identifier for all the check boxes that you are concerned with.

So now all you need to do is work out which times to check on.

I hope this gets you closer to a solution.


Solved it like this:

Linq return bool where a = val1 & b = val2 from model?

0

精彩评论

暂无评论...
验证码 换一张
取 消