I have a dropdown list conatining some options. The last one is "other". When the user chooses the other
option a textbox appears next to the drop down list. When the user chooses "other" he must enter a value into the textbox. Both, the dropdown list and the textbox, point to one single property of the the model.
How do I achieve this using custom validation? what is the best solution?
Asked
Active
Viewed 37 times
0

Marco
- 22,856
- 9
- 75
- 124

user217648
- 3,338
- 9
- 37
- 61
-
Please show us your code. – Marco May 22 '14 at 06:52
-
It really depends on a lot of things. What type is the "value" of the dropdown? If it's `int`, then you have a chance using annotations. If not, my bet would be on JavaScript. – Andrei V May 22 '14 at 06:52
-
the value is int and text is string. – user217648 May 22 '14 at 06:53
1 Answers
0
It seems what you're looking for is conditional validation. A very nice example is already mentioned in another question where you could create a custom RequiredIf
attribute.
The topic has also been addressed frequently on stackoverflow.com
-
thanks but conditional validation is for two properties of the model. as I wrote both textbox and dropdown list are for one property. – user217648 May 22 '14 at 06:56