MVCプロジェクトでFluentValidation(http://fluentvalidation.codeplex.com)を使用して2つのルールを作成したいと思います。
CompanyとNameの両方が空の場合、何も起こりません。それらのいずれかが満たされている場合、何も起こらないはずです。会社または名前のいずれかが入力されていない場合は、両方にラベルを表示します。(エラーメッセージは同じである可能性があります)
私はこれまでこれを試しました:
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage("Please fill in the company name or the customer name")
.Unless(x => !string.IsNullOrWhiteSpace(x.Company));
RuleFor(x => x.Company)
.NotEmpty()
.WithMessage("Please fill in the company name or the customer name")
.Unless(x => !string.IsNullOrWhiteSpace(x.Name));
When、Must、Unlessの組み合わせを試しましたが、どれも機能しません。何も入力しないと、これら2つのプロパティにエラーは表示されません。
誰かが私を助けることができますか?