Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
Is there a chance to check a value within a foreach at the same time? I would like to filter by value and show randomly only one.
Hi Levente
What do you have in mind?
Something like
@foreach (item in Model.News){ if(item.Headline.HasValue){ //Do something } }
Or are you thinking more like
@foreach(item in Model.News.Where("Condition")){ //Do something }
Perhaps you can benefit from the Razor cheetsheet here https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets/ - It's made for Umbraco 6 but should be relevant for v7 as well - Be aware that the one I linked to is for strongly typed razor - If you're using dynamics then you should have a look at this cheatsheet instead https://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
Look for the "Filtering and ordering extensions".
Hope this helps.
/Jan
Definitely the second what I need. Thank you for the links, but I can't deal with it, this is what I have at the moment:
var projectImagesList = CurrentPage.projectImages.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); var projectImagesCollection = Umbraco.Media(projectImagesList); foreach (var projectImage in projectImagesCollection.Where("Visible").Random(1)) { if (imageType == "medium-landscape") { do something } }
And I need to check imageType == "medium-landscape" outside.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor foreach checking value instantly
Hi,
Is there a chance to check a value within a foreach at the same time? I would like to filter by value and show randomly only one.
Hi Levente
What do you have in mind?
Something like
Or are you thinking more like
Perhaps you can benefit from the Razor cheetsheet here https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets/ - It's made for Umbraco 6 but should be relevant for v7 as well - Be aware that the one I linked to is for strongly typed razor - If you're using dynamics then you should have a look at this cheatsheet instead https://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
Look for the "Filtering and ordering extensions".
Hope this helps.
/Jan
Definitely the second what I need. Thank you for the links, but I can't deal with it, this is what I have at the moment:
And I need to check imageType == "medium-landscape" outside.
is working on a reply...