c# - 如何支持为 EPiServer 属性选择多个枚举值?

标签 c# enums episerver episerver-7 episerver-8

我有一个属性,允许用户选择多个枚举值,目前这对于将信息保存到数据库并使用它来说效果很好。但是,它似乎无法正确地将属性中的值读回编辑 UI。

我认为枚举存在某种类型问题,导致 SelectMany 值未按您的预期设置。

我有以下枚举:

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

以及以下ISelectionFactory:

using System;
using System.Collections.Generic;
using System.Linq;

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

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

            return (from object value in values select new SelectItem { Text = this.GetValueName(value), Value = value }).OrderBy(x => x.Text);
        }

        private string GetValueName(object value)
        {
            return value.ToString();
        }
    }
}

然后我将属性添加到 Alloy 演示中的 ContactPage 模型中。

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

有人知道如何解决这个问题吗?

最佳答案

似乎是一个错误。请向 EPiServer 报告。

关于c# - 如何支持为 EPiServer 属性选择多个枚举值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32185447/

相关文章:

c# - 我应该在哪里存储在批处理运行结束时发出的电子邮件的电子邮件模板?

enums - 在 Go 中表示枚举的惯用方式是什么?

c# - FileStream 和设备的异步 I/O

c# - 正则表达式问题 |需要验证数字范围

java - 为什么下面的代码输出 10 3 次而我只创建了一个对象

c# - EPiServer.Configuration.Settings.Instance - 应用程序使用 siteId ="x"的设置进行初始化,但当前请求映射到 siteId ="y"

EPiServer 7 (MVC) LinkItemCollection : add images to LinkItem collection?

来自 EPiServerUI.master 的 Episerver 嵌套母版页

C# WPF SshClient无法访问Mysql提示

c - 枚举名称有什么作用?