Welcome to the navigation

Nostrud laborum, nisi et esse ad exercitation labore duis proident, nulla dolore occaecat id non adipisicing ullamco excepteur ea anim ut veniam, elit, est voluptate. Sit aliquip minim elit, mollit ullamco ut nulla qui tempor reprehenderit sunt aliqua, proident, est et officia nisi id adipisicing dolore in excepteur laborum, aute

Yeah, this will be replaced... But please enjoy the search!

Get categories from EPiServer block

Categories Tags

The blocks in EPiServer include the Category property but the BlockData object does not expose any category property in code. The solution is to cast the BlockData object to ICategorizable.

(currentBlock as ICategorizable).Category

A typical usage scenario for me would be to fetch what I need in the controller and put it in the ViewModel.

public class ParallaxNavigationBlockController : BlockController<ParallaxNavigationBlock>
{
    public override ActionResult Index(ParallaxNavigationBlock currentBlock)
    {
        var model = new ParallaxNavigationViewModel
        {
            Category = (currentBlock as ICategorizable).Category.GetCategories().FirstOrDefault()
        };

        return PartialView(model);
    }
}

// ViewModel
public class ParallaxNavigationViewModel
{
    public Category Category { get; set; }
}

// Extension method for categories
public static IEnumerable<Category> GetCategories(this CategoryList categoryList)
{
    CategoryRepository categoryRepository = ServiceLocator.Current.GetInstance<CategoryRepository>();
    return categoryList.Select(x => categoryRepository.Get(x));
}
Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author