var cts = ApplicationContext.Current.Services.ContentTypeService;
var masterDocTypeId = cts.GetContentType("Brand").Id;
var cs = ApplicationContext.Current.Services.ContentService;
var brands = cs.GetContentOfContentType(masterDocTypeId);
...
<p class="text-center">
@foreach (var brand in brands)
{
dynamic b = Umbraco.Content(brand.Id);
<p>@b.Name</p>
}
</p>
Vlad I would have a look at Object Relational Mappers like Glass
It would stop you having to put magic strings in like 'Brand'. Also i would abstract this is to a helper class and call it. Also i would put some exception handling in
Sort content in partial view
Hi
I have the following partial view:
...
How can I sort brands by a certain property?
Thanks V.
Hi Vlad,
GetContentOfContentType returns IEnumerable of Content items, you don't need 'dynamic b = Umbraco.Content(brand.Id);'
Try to sort like :
Thanks,
Alex
Thanks Alex
Vlad I would have a look at Object Relational Mappers like Glass It would stop you having to put magic strings in like 'Brand'. Also i would abstract this is to a helper class and call it. Also i would put some exception handling in
But as Alex says for sure. Just do an OrderBy()
Thanks, Charles, great suggestions. I think if we need just sort items on presentation layer, OrderBy is enough.
Alex
is working on a reply...