【问题标题】:How to create list of radio button list using Enum and bind them to model?如何使用 Enum 创建单选按钮列表并将它们绑定到模型?
【发布时间】:2020-02-04 09:56:41
【问题描述】:

我有两组枚举来生成单选按钮列表。 1) 生成可用功能的标签和 2) 生成固定值集作为单选按钮。如何将此类单选按钮值绑定到模型以便将它们发布到控制器?我的用户界面如下所示:

可用功能:

公共API

Enabled  Disabled

私有API

Enabled Disabled

身份验证

Enabled Disabled

下面是我的模型:

public enum Features
    {
        PublicAPI = 1,
        PrivateAPI,
        Authentication
    }

public enum FeatureState
    {
        Enabled,
        Disabled,
    }

public class MyModel
{
public Dictionary<Features, FeatureState> FeatureSettings{ get; set; }
}

【问题讨论】:

  • 可以参考链接link

标签: asp.net-mvc


【解决方案1】:

我试过了,我不知道天气你想要输出应该是这样还是什么

       public enum Features
    {
        PublicAPI = 1,
        PrivateAPI,
        Authentication
    }

    public enum FeatureState
    {
        Enabled,
        Disabled,
    }
    public Dictionary<Features, FeatureState> FeatureSettings { get; set; }


    public ActionResult Index()
    {

        FeatureSettings = new Dictionary<Features,FeatureState>();
        foreach (Features foo in Enum.GetValues(typeof(Features)))
        {
            FeatureSettings.Add((Features)foo, (FeatureState)foo);
        }

        return View();
    }

【讨论】:

    猜你喜欢
    • 2011-03-29
    • 2017-05-24
    • 2013-06-29
    • 2021-07-19
    • 2020-01-19
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多