私のモデルには、次のタイプのHomeAddressとBillingAddressを持つ人がいます。
class Person {
public Location HomeAddress { get; set; }
public Location BillingAddress { get; set; }
... other properties
}
class Location {
[Required]
public string ZipCode { get; set; }
... other properties
}
必須プロパティHomeAddressでのみ「必須」プロパティを検証するエレガントな方法を探しています。私は通常のcomponentmodel属性を使用しており、MVCからの組み込みモデル検証を使用しています。したがって、私が探しているのは、LocationがPerson.HomeAddressまたは.BillingAddressにあるかどうかをチェックし、最初のケースでのみ検証する属性です。または、十分な情報が入力されていない場合に備えて、デザインを変更してバインディングアドレスをNULLにする必要がありますか?