If this is my view model:
public class ViewModel{
public string SimpleProperty{get;set;}
public SubViewModel ComplexProperty{ get;set;}
public SubViewModel[] ComplexPropertyArray{ get; set; }
}
public class SubViewModel{
public string NestedSimpleProperty{get;set;}
}
Then what would be the default error message keys assigned to a ModelStateDictionary
for:
ViewModel.SimpleProperty(see update below)ViewModel.ComplexProperty(see update below)ViewModel.ComplexProperty.NestedSimpleProperty(see update below)ViewModel.ComplexPropertyArray(see update below)- ViewModel.ComplexPropertyArray[0]
- ViewModel.ComplexPropertyArray[0].NestedSimpleProperty
Update I found this in reflector:
protected internal static string CreateSubPropertyName(string prefix, string propertyName)
{
if (string.IsNullOrEmpty(prefix))
{
return propertyName;
}
if (string.IsNullOrEmpty(propertyName))
{
return prefix;
}
return (prefix + "." + propertyName);
}
So, I think that covers everything except for #5 and #6
If you make the
NestedSimpleProperty
required:and then you have a form in which you have multiple textboxes for this property corresponding to each item in the
ComplexPropertyArray
collection then the key that will be used for error messages will beComplexPropertyArray[i].NestedSimpleProperty
wherei
represents the index of the element in the array which contains an empty value.