如何在mvc中查看页面中使用枚举 [英] how to use enum in viewing page in mvc

查看:371
本文介绍了如何在mvc中查看页面中使用枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在cs我有以下



  public  枚举 AppointmentStatus 
{
[描述( #008800:查询)] // 绿色
查询= 0
[描述( #FF8800:BOOKED )] // orange
预订,
[说明( #CC0000:CONFIRMED)] // red
确认
}


db状态中的
存储为0 ,1,2

如何显示列表页面已确认,预订,查询基于枚举

解决方案

您可以在我的一篇关于枚举的文章中找到相关的代码片段,其中一篇:人类可读的枚举元数据 [ ^ ]。



请注意:我正在使用自己的 [描述] 属性,但您可能使用 System.ComponentModel.DescriptionAttribute 。这并不重要,使用属性的算法将完全相同。这些属性在运行时通过反射使用。



-SA


in cs i have following

public enum AppointmentStatus
  {
      [Description("#008800:ENQUIRY")] // green
      Enquiry = 0,
      [Description("#FF8800:BOOKED")] // orange
      Booked,
      [Description("#CC0000:CONFIRMED")] // red
      Confirmed
  }


in db status is stored as 0,1,2
how to show list page as confirmed,Booked ,enquiry based on enum

解决方案

You can find relevant fragment of code in one of my articles on enumerations, this one: Human-readable Enumeration Meta-data[^].

Please, be careful: I'm using my own [Description] attribute, but you probably use System.ComponentModel.DescriptionAttribute. It does not really matter, the algorithm of using attributes would be exactly the same. The attributes are used during runtime via reflection.

—SA


这篇关于如何在mvc中查看页面中使用枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆