T
T
Timur Tuz2015-12-07 22:26:29
ASP.NET
Timur Tuz, 2015-12-07 22:26:29

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

1 answer(s)
T
Timur Tuz, 2015-12-08
@TTA

At the stage of checking the model, when editing, I simply brought all the child classes with the parent one and then it worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question