servicestack,data-annotations,C#,Api,servicestack,Data Annotations" /> servicestack,data-annotations,C#,Api,servicestack,Data Annotations" />

C# 服务堆栈[必需]批注不起作用

C# 服务堆栈[必需]批注不起作用,c#,api,servicestack,data-annotations,C#,Api,servicestack,Data Annotations,我有一个模型,并在其上添加了所需的注释,但它没有任何作用。它不会抛出任何错误。我是否必须向配置中添加一些内容以确保触发注释 using System.ComponentModel.DataAnnotations; [ApiMember(Description = "The student ID to lookup", IsRequired = true, ParameterType = "form")] [Required] public int? StudentId { get; se

我有一个模型,并在其上添加了所需的注释,但它没有任何作用。它不会抛出任何错误。我是否必须向配置中添加一些内容以确保触发注释

using System.ComponentModel.DataAnnotations;

 [ApiMember(Description = "The student ID to lookup", IsRequired = true, ParameterType = "form")]
 [Required]
 public int? StudentId { get; set; }

[Required]
属性可以在数据模型中用于注释不可为空的字段,但它对ServiceStack DTO没有任何影响

要验证DTO,建议使用