Razor get specific item from specicific row in a list

Sep 28, 2013 at 10:08 AM
Hi

As I am slowly changing all my work from Form and List and my Razor templating is not up to par with my XSL just yet

I already have my listing template setup and working but before I have the full listing display as I have now I want to reuse the image from the first row.

In a razor list what would be the best way to get for instance the Image field of the first row
Developer
Sep 30, 2013 at 8:56 AM
Hi nokiko

Please try the following example:
@* Prevent Error when there is no "first" item *@
@if(List.Count > 0)
{
    // Get First Content-Element in the List
    var First = List[0].Content;
    
    <img src="@First.Image" alt="@First.Title" />
}
... or you can also use List[0].Content directly, without setting a variable:
@* Prevent Error when there is no "first" item *@
@if(List.Count > 0)
{
    <img src="@List[0].Content.Image" />
}
Please let me know if you got it working.

Regards
Raphael
Sep 30, 2013 at 7:38 PM
that worked perfectly

thanks