Hi,
I have a problem merging two selection into one variable. I have tried using concat but I cannot figure out the correct syntax, or perhaps I should use another approach?
Any help would be greatly appreciated :-)
// Selection 1
var Coll1= homePage1.Descendants("Ledig").Where("Fastid = @0", @Lokal.Fastid).FirstOrDefault();
var image1 = Coll1.Bilds.FirstOrDefault();
// Selection 2
var Coll2= homePage1.Descendants("Ledig2").Where("FastighetsId = @0", @Lokal.Fastid).FirstOrDefault();
var image2 = Coll2.Bilds.FirstOrDefault();
// MERGE SELECTIONS
var image12= image1.Concat(image2); //This does not work!
//Code generating output data
@{if(image12!= null)
{
// do something
<a href="@image12.bildfil" data-lightbox="[email protected]@Lokal.Objektsid" data-title="@image12.Bildrubrik">
<!-- Use ImageGen querystring to automatically generate a thumbnail & setup fallback image -->
<img style="vertical-align: middle;" src="/[email protected]&height=120&width=200&crop=resize&align=center&altImage=/Media/no-image.png" alt="@image12.Name"/>
</a>
}
}
</div>
}
You are trying to merge two individual elements together, which fundamentally isn't possible because how would the system know which properties to replace etc.
What you can do is this:
var myCombinedList = new List<IPublishedContent>();
myCombinedList.Add(image1);
myCombinedList.Add(image2);
Then you can do the following:
foreach(image in myCombinedList)
{
<div>@image.Name</div>
}
This would output the name of both of the images one after the other.
Merge two selections into one
Hi, I have a problem merging two selection into one variable. I have tried using
concat
but I cannot figure out the correct syntax, or perhaps I should use another approach?Any help would be greatly appreciated :-)
Hi Martin
Can you show all code?
Alex
Hi,
I have added the code that generates html code showing the images and text. Note that my code works fine if I only use either 'image1' or 'image2'.
For example
var image12= image1;
will make the code work fine (but of course I then miss the data fromimage2
).Hi Martin,
You are trying to merge two individual elements together, which fundamentally isn't possible because how would the system know which properties to replace etc.
What you can do is this:
Then you can do the following:
This would output the name of both of the images one after the other.
Does that help?
Nik
Ok thanks you, I will try this. I let you know if it works.
It didn't work well, Trying to use
myCombinedList.Add(image1);
throws server error.One idea I have is to combine
Coll1.Bilds
andColl2.Bilds
before selectingFirstOrDefault()
.I should point out that Bild is a doc type and Bilds will thus contain the elements found all pages based on doc type Bild ( i.e. .[DocTypeName]s ) .
Do you think that would make it easier?
Martin, are you sure that these lines are working?
What is "Bilds"?
Hi,
Yes it works fine. 'Bild' is a document type. I will try Nik's suggestion och hope it works.
is working on a reply...