Sunday 15 May 2011

c# - RequiredAttribute depending on Parent-Property-Attributes -



c# - RequiredAttribute depending on Parent-Property-Attributes -

for asp.net mvc 5 application utilize more or less complex , nested models.

so have model class:

public class mainmodel{ [required] public string foo {get;set;} [required] public localizedstringmodel bar1 { get;set;} // not required public localizedstringmodel bar2 { get;set;} }

as see, 2 properties of model class type of model class.

public class localizedstringmodel { [required] public string defaulttranslation { get;set;} public ilist<string> moretranslations {get;set;} }

now problem is, because of requiredattribute in localizedstringmodel-class validation done both properties of mainmodel class. there way validation required localizedstringmodel-property?

i tried implementing custom requiredwhenparent-attribute, have no access parent mainmodel-instance localizedstringmodel instance. :-(

someone idea?

c# asp.net-mvc validation required model-validation

No comments:

Post a Comment