0
客戶端驗證正在'公司名'工作正常,但對於繼承類,即運輸&結算其不起作用。請建議解決方案。FluentValidation客戶端驗證不適用於繼承類
[Validator(typeof(ClientValidator))]
public class Client
{
public string CompanyName{get;set;}
private volatile Contact Shipping = null;
private volatile Contact Billing = null;
}
public class Contact : Address
{
}
public class Address
{
public String Name{get;set;}
public String Phone{get;set;}
}
public class ClientValidator : AbstractValidator<Client>
{
public ClientValidator()
{
RuleFor(x => x.CompanyName).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Shipping.Name).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Shipping.Phone).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Billing.Name).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
RuleFor(x => x.Billing.Phone).NotNull().WithMessage("Required").Length(1, 15).WithMessage("Length issue.");
}
}
感謝它的工作。 –