Met*_*eta 22 c# data-annotations asp.net-core
我在我的域模型类上使用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 Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Gui*_*rte 43
ASP.NET核心使用
Microsoft.AspNetCore.Mvc **ModelMetadataType**
Run Code Online (Sandbox Code Playgroud)
代替
System.ComponentModel.DataAnnotations.**MetadataType**
Run Code Online (Sandbox Code Playgroud)
尝试将您的属性更改为 [ModelMetadataType(typeof(ComponentModelMetaData))]
| 归档时间: |
|
| 查看次数: |
10296 次 |
| 最近记录: |