I have a foreach with multiple conditions and it just seems like a bloated way to do the tests. Is there a shorter way to write this? We are using 4.11 and will be switching to ver 6 in a few months.
If you are using the legacy Razor Macros you maybe be able to use the .ContainsAny method, this will also be available in v6.2 and v7.1.2 when using MVC (see here)
It would be something like this (untested):
var keywords = new List<string> {"Category2InternalPage", "ExternalLink", "StudentGroupsPage"};
@foreach (var node in page.Children.Where("Visible && NodeTypeAlias.ContainsAny(@0)", keywords))
Better Syntax?
I have a foreach with multiple conditions and it just seems like a bloated way to do the tests. Is there a shorter way to write this? We are using 4.11 and will be switching to ver 6 in a few months.
Hi Steve,
You can do this:
If you are using the legacy Razor Macros you maybe be able to use the .ContainsAny method, this will also be available in v6.2 and v7.1.2 when using MVC (see here)
It would be something like this (untested):
Jeavon
Thanks Jeavon! This is great! Is the @1 Razors way of doing C# placeholders? {0}
is working on a reply...