Last active
March 6, 2019 21:02
-
-
Save technomaz/f89fa2aedaa97cb2a7d12d65fe35cfbd to your computer and use it in GitHub Desktop.
When using a list view to show only a single entry, such as an academic program, use the following code to grab the first item in the list of items returned.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ItemViewModel GetFirstItemViewModel(this DynamicContentListViewModel listModel) | |
{ | |
ItemViewModel item = null; | |
if (listModel.Items.Any()) | |
{ | |
item = listModel.Items.First(); | |
} | |
return item; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Models.DynamicContentListViewModel | |
@using Telerik.Sitefinity.Frontend.Mvc.Helpers; | |
@using Telerik.Sitefinity.Frontend.Mvc.Models; | |
@using cusitefinity.Foundation.CuSitefinityFoundation.Helpers; | |
@{ | |
ItemViewModel item = Model.GetFirstItemViewModel(); | |
} | |
@if (item != null) | |
{ | |
// cshtml code // | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment