相关疑难解决方法(0)

ASP.NET Core MetaDataType属性不起作用

我在我的域模型类上使用MetaDataType属性.它应该将属性信息从引用的类移动到已设置MetadataType属性的类中.但它没有像宣传的那样做.造成这个问题的原因是什么?

[MetadataType(typeof(ComponentModelMetaData))]
public partial class Component
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection<Repo> Repos { get; set; }
    public string Description { get; set; }   
}


public class ComponentModelMetaData
{
    [Required(ErrorMessage = "Name is required.")]
    [StringLength(30, MinimumLength = 3, ErrorMessage = "Name length should be more than 3 symbols.")]
    public string Name { get; set; }
    public ICollection<Repo> Repos { get; set; }
    [Required(ErrorMessage = "Description is required.")]
    public string …
Run Code Online (Sandbox Code Playgroud)

c# data-annotations asp.net-core

22
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

c# ×1

data-annotations ×1