November Happy Hour will be moved to Thursday December 5th.

Category Selection List in Block

Vote:
 

I'm trying to create an MVC block which will allow the user to select a category from all available categories to affect some programatically defined items. (IE Select 'shoes' to show some calculated shoe results, or 'TVs' etc etc)

In my block definition I have:

[Editable(true)]
[Display(Name = "Category Selection",
Order = 1)]
[SelectOne(SelectionFactoryType = typeof(CategorySelectionFactory))]
public virtual CategoryList Category { get; set; }

Which I was hoping would give me a select list of available categories for the user to choose from. However when I'm running the solution and going to the block I'm getting the following error:

Unable to cast object of type 'EPiServer.Business.Commerce.VisitorGroupsCriteria.CategorySelectionFactory' to type 'EPiServer.Shell.ObjectEditing.ISelectionFactory'

But from what I can see CategorySelectionFactory does implement ISelectionFactory, so I'm not sure what I'm missing here to cause this error. If I am meant to inject an instance of CategorySelectionFactory I'm not sure how to do that for an MVC block.

Sorry if this is a relatively basic question, I'm relatively new to EPiServer development, and any help would be appreciated.

#143038
Jan 11, 2016 10:25
Vote:
 

Sorry I should mention that this is for EPiServer Commerce

#143050
Jan 11, 2016 15:17
Vote:
 

If the list should contain all categories defined in EPiServer you can remove the SelectOneAttribute from your property. This is the only thing you need:

[Display(Name = "Category Selection", Order = 1)]
public virtual CategoryList Category { get; set; }
#143146
Jan 13, 2016 15:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.