开发者

Trying to force some kind of IEnumerable.Each-method

开发者 https://www.devze.com 2023-04-07 05:46 出处:网络
I have the following snipped inside a Razor-file: <td>@item.Mottakere.All(q => { @q.Epost <br />

I have the following snipped inside a Razor-file:

<td>@item.Mottakere.All(q => {
    @q.Epost <br />
})</td>

Where @item is a object from a foreach ... Model.ToList() and @item.Mottaker is a List inside this object.

I know this doesn't work, mostly because All expects a bool, and also because I can't inline razor in a lambda this way... But is there any way I could force this kind of function开发者_运维问答ality? Or should I just do a normal nested foreach ?


I invite you to checkout Templated Razor Delegates.


All doesn't expect bool, but it returns true when the given lambda is true for every item in the list - for example Are all apples in the list red?

In your case, when you want to output the elements in Mottakere, you'll have to use another foreach or use some helper method. For example see this.

0

精彩评论

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