我想知道每个人对此的看法。代码容易遵循吗?还是有更好的方法来做到这一点?顺便说一下,这就是我目前正在使用ASP.NET MVC进行验证的方式。我可以遵循,但我是撰写它的人。由于某种原因,SO正在删除验证器之间的换行符。
public override Validation<MemberCreate> ValidationRules()
{
var validation = new Validation<MemberCreate>();
validation.Add(x => x.Name)
.LengthBetween(
Config.Member.NameMinLength,
Config.Member.NameMaxLength,
Resources.Errors.LengthBetweenNotValid.Fmt(
Resources.Titles.Name,
Config.Member.NameMinLength,
Config.Member.NameMaxLength))
.Characters(Resources.Errors.CharactersNotValid.Fmt(Resources.Titles.Name));
validation.Add(x => x.EmailAddress).Email(
Resources.Errors.EmailNotValid.Fmt(
Resources.Titles.EmailAddress));
validation.Add(x => x.VerifyEmailAddress).Equal(
x => x.EmailAddress,
Resources.Errors.CompareNotValid.Fmt(
Resources.Titles.VerifyEmailAddress,
Resources.Titles.EmailAddress));
validation.Add(x => x.PassWord).LengthGreaterThan(
Config.Member.PassWordMinLength,
Resources.Errors.LengthGreaterThanNotValid.Fmt(
Resources.Titles.PassWord,
Config.Member.PassWordMinLength));
validation.Add(x => x.VerifyPassWord).Equal(
x => x.PassWord,
Resources.Errors.CompareNotValid.Fmt(
Resources.Titles.VerifyPassWord,
Resources.Titles.PassWord));
return validation;
}
最佳答案
我会出于清教理由投赞成票-格式不一致,并且看不到任何评论。
务实地,您可以花一点功夫就能跟上您的工作。
关于c# - 该ASP.NET MVC验证代码是否易于阅读和遵循?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/398801/