小编Dan*_*Dan的帖子

ASP.NET Core 绑定到字典

在 ASP.NET Core 中,可以绑定字典值吗?

我在这个相关问题的最新答案 (不是标记正确的答案)中看到它指出:

在 ASP.NET MVC 4 中,默认模型绑定器将使用典型的字典索引器语法 property[key] 绑定字典。

对于 ASP.NET Core MVC(和/或 Razor Pages)来说也是如此吗?

c# dictionary model-binding asp.net-core-mvc asp.net-core

7
推荐指数
1
解决办法
6295
查看次数

EF Core 中的枚举列表

是否可以在使用 EF Core 的项目中使用枚举列表来存储数据?

我的枚举:

   public enum AudienceType
    {
        Child,
        Teen,
        [Display(Name ="Young Adult")]
        YoungAdult,
        Adult,
        Elderly
    }
Run Code Online (Sandbox Code Playgroud)

使用枚举的类:

public class Restaurant
{
    public int Id { get; set; }
    [Required, StringLength(80)]
    public string Name { get; set; }
    [Display(Name="Select the target audiences")]
    public List<AudienceType> AudienceTypes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行时add-migration AudienceType,出现以下错误:

PM> add-migration AudienceType
Build started...
Build succeeded.
System.InvalidOperationException: The property 'Restaurant.AudienceTypes' could not be mapped, because it is of type 'List<AudienceType>' which is not a …
Run Code Online (Sandbox Code Playgroud)

enums list asp.net-core ef-core-3.1

6
推荐指数
1
解决办法
5475
查看次数