zoukankan      html  css  js  c++  java
  • Razor

    //
    //仅供学习,注明出处。
    //PlanUseOfDrugsVM页面层对象模型
    //这里是Controller控制器方法。通过制定方法获取枚举,运用ViewData存取键值对数据
     public IList<PlanUseOfDrugsVM> GetIntervalType()
    {
    IList<PlanUseOfDrugsVM> list = new List<PlanUseOfDrugsVM>();
    IDictionary<int, string> dic = new GetDicFromEnum().Get(typeof(IntervalEnum));
    list.Add(new PlanUseOfDrugsVM
    {
    Interval = null,
    IntervalName = "请选择..."
    });
    foreach (var p in dic)
    {
    list.Add(new PlanUseOfDrugsVM { Interval = p.Key, IntervalName = p.Value });

    }
    return list;
    }
    //仅供学习,注明出处。
    public class GetDicFromEnum
    {
    ///<summary>
    /// 根据一个枚举类型得到一个IDictionary格式如下
    /// public enum Folk
    /// {
    /// [Description("汉族")]
    /// HanZu,
    /// [Description("回族")]
    /// Huizi
    /// }
    ///</summary>
    ///<param name="enumType">枚举类型</param>
    ///<returns>IDictionary列表</returns>
    public IDictionary<int, string> Get(Type enumType)
    {
    IDictionary<int, string> ht = new Dictionary<int, string>();
    Type typeDescription = typeof(DescriptionAttribute);
    System.Reflection.FieldInfo[] fields = enumType.GetFields();
    string strText = string.Empty;
    int strValue = 0;
    foreach (FieldInfo field in fields)
    {
    if (field.FieldType.IsEnum == true)
    {
    strValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null));
    if (strValue >= -1)
    {
    object[] arr = field.GetCustomAttributes(typeDescription, true);
    if (arr.Length > 0)
    {
    DescriptionAttribute aa = (DescriptionAttribute)arr[0];
    strText = aa.Description;
    }
    else
    {
    strText = field.Name;
    }
    ht.Add(strValue, strText);
    }
    }
    }

    return ht;
    }
    }
    }
    //仅供学习,注明出处。
    //前台DropDownList引用
    
    
    
    
     @Html.LabelFor(model => model.MType):
    @Html.DropDownListFor(model => model.MType,
    ViewData["GetIntervalType"] as SelectList, new { @style = "160px" })




  • 相关阅读:
    SPARK 中 DriverMemory和ExecutorMemory
    Logistic Regression vs Decision Trees vs SVM: Part II
    Logistic Regression Vs Decision Trees Vs SVM: Part I
    Scala _ [underscore] magic
    spark-shell --conf
    spark-submit [options]
    maven 将依赖的jar包打入jar包中
    log4j
    eclipse java工程和maven工程的互相转换
    插件上传2
  • 原文地址:https://www.cnblogs.com/zjmzone/p/2232719.html
Copyright © 2011-2022 走看看