asp.net mvc - Custom Required attribute - property required depending of parent model value -


i have model productmodel has: * bool isnew property * productdetailsmodel details property

public class productmodel {     public bool isnew { get; set; }     public productdetails details { get; set; } }  public class productdetails {     public string code { get; set; }     public string type { get; set; }     public string description { get; set; }     public int number { get; set; } } 

productdetails has other properties eg. code, type, description, number

i make description , number property of productdetailsmodel required if isnew of productmodel set true.

how it?

btw have more properties of custom types within productmodel , can't move properties single productmodel.

i found answer here asp.net mvc conditional validation

it seems easiest way implement validation in product model.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -