This is just an odd quirk which popped into my head:
A simple solution might be to subclass Address to OptionalAddress.
I don't think the Required attributes would be inherited to the child class.
[AttributeUsage (Inherited = False)]
also comes to mind if needed.
A more MVCish solution might be to implement a custom model binder (completely untested):
public override object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext)
{
var address = base.BindModel(controllerContext, bindingContext) as Address;
if (bindingContext.ModelName.EndsWith("BillingAddress"))
{
foreach (PropertyInfo p in address.GetType().GetProperties())
{
Attribute a = Attribute.GetCustomAttribute(p, typeof(RequiredAttribute));
if (a != null
&& propertyInfo.GetValue(address, null) == null
&& bindingContext.ModelState[bindingContext.ModelName
+ "." + p.Name].Errors.Count == 1)
{
bindingContext.ModelState[bindingContext.ModelName + "." + p.Name].Errors.Clear();
}
}
return address;
}