Answer the question
In order to leave comments, you need to log in
How to make different validation rules for the same model?
Colleagues only deal with asp.mvc. Tell me how to "racially correct" solve the problem:
There is a Transport class that has fields: Name, Type, Tires, Wings
And there are, say, 2 entities:
Name : Truck Type : auto Tires : 4
And
Name : Aircraft Type : jet Wings : 2
In both cases, all fields that relate to a specific Type are required (example: Name, Type, Wings are required for jet).
How to organize such validation? I did:
1. General class, in which I added the Required rule for Name and Type.
2. Inherited from it 2 classes Auto and Jet in which I added this rule for fields specific to this type of transport.
But now it turns out that I need to create CRUD functionality for each inherited class?
Because when I send a model to a view, it asks for typing either one model or the other.
I don't know how to do it better? Maybe not fence the garden with inheritance and somehow dynamically assign rules (by the way, I did not find how to do this)?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question