2015-08-24 46 views
2

我有一個屬性,它允許用戶選擇多個枚舉值,並在此刻這適用於將信息保存到數據庫和使用它。但是,它似乎沒有正確地將屬性值讀回編輯UI。如何支持爲EPiServer屬性選擇多個枚舉值?

我認爲有某種類型的問題與枚舉導致SelectMany值不按照您的預期設置。

我有以下枚舉:

public enum Skills 
{ 
    People, 
    IT, 
    Management, 
    Sales, 
} 

而下面ISelectionFactory

​​

然後,我有我已經加入到合金演示的ContactPage模型的屬性。

[SelectMany(SelectionFactoryType = typeof(EnumSelectionFactory<Skills>))] 
    public virtual string EmployeeLevels { get; set; } 

有沒有人知道如何解決這個問題?

回答

1

設置底層值類型...

namespace TestSite.Business.EditorDescriptors 
{ 
    using EPiServer.Shell.ObjectEditing; 

    public class EnumSelectionFactory<TEnum, TUnderlying> : ISelectionFactory 
    { 
     public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata) 
     { 
      var values = Enum.GetValues(typeof(TEnum)); 

      return (from TEnum value in values select new SelectItem { Text = this.GetValueName(value), Value = Convert.ChangeType(value, typeof(TUnderlying)) }).OrderBy(x => x.Text); 
     } 

     private string GetValueName(object value) 
     { 
      return Enum.GetName(typeof(TEnum), value); 
     } 
    } 
} 

...用一個字符串類型的模型來實現......

[SelectMany(SelectionFactoryType = typeof(EnumSelectionFactory<Skills,string>))] 
public virtual string EmployeeLevels { get; set; } 
2

似乎是一個錯誤。請報告給EPiServer。

+0

謝謝,我已經給他們發郵件,讓我們看看他們說什麼:)。 –