LINQ的回报布尔其中a = VAL1&安培;从模型B = val2的? [英] Linq return bool where a = val1 & b = val2 from model?
本文介绍了LINQ的回报布尔其中a = VAL1&安培;从模型B = val2的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个for循环,需要根据当前的人来检查,如果模型中包含的值。
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())%>
<%} %>
不知怎的,我需要做的检查复选框如果模型包含基于2个参数的数据(我只是把第一个循环那里)
Somehow I need to make the checkbox checked if the model contains data based on 2 parameters (i just put the first loop there)
木田,如:
<%= Html.CheckBox("TimeRange..", (bool)Model.Timetable.Contains(x => x.Time == timeval && x => x.DayOfWeek = i))%>
如何做呢?
/ M
推荐答案
我任何你想要 任何
而不是 包含
和你的语法有点过。试试这个:
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)
请注意,它只有一个拉姆达前pression,所以只有一个 X =&GT;
位,同时注意 ==
而不是 =
中的第二个条件。
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.
这篇关于LINQ的回报布尔其中a = VAL1&安培;从模型B = val2的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文