c# - 如何将 ENUM 值转换为 String 从 View 到 Controller

标签 c# asp.net asp.net-mvc enums

所以我已经知道如何获取字符串、整数、小数,现在我在枚举的这一部分苦苦挣扎。如何将枚举转换为字符串

**Enum statecode = apsp.Customer.BillingAddress.StateCode.Value;**
Customer = new Customer()
       {
         FirstName = fn,
         LastName = ln,
         BillingAddress = new Address
             {
              StreetAddress1 = street1,
              StreetAddress2 = street2,
              City = city,
              **StateCode = statecode**,
              ZipCode = zipcode
              }
        },

所以我想插入这个的值..

Enum statecode = apsp.Customer.BillingAddress.StateCode.Value;

到这个枚举

StateCode = statecode,

最佳答案

Enum statecode = apsp.Customer.BillingAddress.StateCode;
Customer = new Customer()
   {
     FirstName = fn,
     LastName = ln,
     BillingAddress = new Address
         {
          StreetAddress1 = street1,
          StreetAddress2 = street2,
          City = city,
          StateCode = (StateCode)statecode,
          ZipCode = zipcode
          }
    },

关于c# - 如何将 ENUM 值转换为 String 从 View 到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42790194/

相关文章:

c# - 向 MySQL 插入多个对象

c# - 替换 .net Web 应用程序中的静态变量

c# - 加载此程序集会产生与其他实例不同的授权集

html - 如何单独且排他地更改 btn-group 颜色?

C# linq group by 在同一实体中的不同键上

c# - ASP.NET 自定义配置文件 serializeAs 属性

asp.net - 覆盖应用程序根 URL 会创建一个不可用的页面

javascript - 如何将 onclick 事件添加到 Razor View 中的单选按钮

c# - 事务 - 避免插入时发生冲突

c# - Web 应用程序身份验证