I ve been trying to implement form validation correctly and a discussion on fubu mailing list has been the most helpful (http://groups.google.com/group/fubumvc-devel/browse_thread/thread/d54b135fe0254653/12180cd86e9dc50b). I m still not entirely clear on certain points, I m a newbie so I m going through some yak shaving.
It seems like the example given in the discussion performed the validation within the controller itself using IsValid(model).
我试图避免这种情况,将我的投入模式与必要的验证特性加以校正,然后利用验证组合在失败时进行转让(通过政策)。
this.Validation(x => {
x.Actions
.Include(call => call.HasInput && call.InputType().Name.EndsWith("Input"));
x.Failures
.ApplyPolicy<AccountValidationFailedPolicy>();
});
这里的等级是对政策施加影响:
public class AccountValidationFailedPolicy : IValidationFailurePolicy {
public bool Matches(ValidationFailure context) {
return (context.InputType() == typeof (RegisterAccountInput));
}
public void Handle(ValidationFailure context) {
var incomingRequest = (RegisterAccountInput) context.InputModel;
var failedValidation = new RegisterationFailedNotification {
CVV = incomingRequest.CVV,
AcceptTerms = incomingRequest.AcceptTerms,
Countries = incomingRequest.Countries,
PhoneNumber = incomingRequest.PhoneNumber,
PIN = incomingRequest.PIN
};
FubuContinuation.TransferTo(failedValidation);
}
}
处理只是试图通过新的模式向另一个行动转移,把价值复制到新的模式中,以便我能够再次以形式展示这些价值观。
I must be doing something wrong here, because it s not transferring anywhere. I have a class with this method which I was hoping would handle it.
public AccountViewModel New(RegisterationFailedNotification notification) { .... }
我在这里看一看,或者我没有看到什么基本东西? 也许政策不是在这里做什么?