Skip to content

Instantly share code, notes, and snippets.

@technomaz
Last active March 6, 2019 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technomaz/f89fa2aedaa97cb2a7d12d65fe35cfbd to your computer and use it in GitHub Desktop.
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.
public static ItemViewModel GetFirstItemViewModel(this DynamicContentListViewModel listModel)
{
ItemViewModel item = null;
if (listModel.Items.Any())
{
item = listModel.Items.First();
}
return item;
}
@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