使用元数据类时,Blazor验证不起作用

时间:2020-04-23 01:15:37

标签: blazor-server-side blazor-editform

我正在使用blazore服务器端。使用Metadata类时,表单验证不起作用。我正在使用脚手架,并且数据库模型是自动生成的。如果我修改了它,则会清除所有的Dataannotation验证。

这是我正在使用的课程

public partial class RequestHelp
{
    public Guid ID { get; set; }
    public Guid UserID { get; set; }
    public string HelpFor { get; set; }
    public string TypeOfHelp { get; set; }
    public string Description { get; set; }
    public DateTime UTCDateCreated { get; set; }
    public DateTime UTCLastUpdateDate { get; set; }
    public string CurrencyCode { get; set; }
    public decimal? Amount { get; set; }
    public bool? IsDeleted { get; set; }
}



[MetadataType(typeof(RequestHelpMetaData))]
public partial class RequestHelp
{

}
public class RequestHelpMetaData
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid ID { get; set; }

    [Required(ErrorMessage = "Please select Who needs Help.")]
    public string HelpFor { get; set; }

    [Required(ErrorMessage = "Please select What kind of Help you are Requesting.")]
    public string TypeOfHelp { get; set; }

    [Required(ErrorMessage = "Please Currency.")]
    public string CurrencyCode { get; set; }

    [Required(ErrorMessage = "Amount Field is required")]
    [Range(1, 999999999999999, ErrorMessage = "Please enter positive number")]
    public decimal? Amount { get; set; }

    [Required(ErrorMessage = "Please enter Details about what you need help for.")]
    [StringLength(4000,MinimumLength=10, ErrorMessage = "Please eneter some details about the help you need")]
    public string Description { get; set; }


}
}

这就是我在烈火中使用它的方式。

<EditForm Model="@_requesForHelp" OnValidSubmit="@HandleValidSubmit">
                <DataAnnotationsValidator />

                <ValidationSummary />
 </EditForm>

0 个答案:

没有答案