10K35H 5H4KY4
10K35H 5H4KY4

Reputation: 1526

MVC 4 clientside validation for textbox with dynamically swtichable datatype

I am Novices to MVC 4. I have one dynamically generated textbox; In my form there is also option to choose the data-type of this textbox like numeric, alphanumeric, integer or date. Therefore, I will only know the excepted data-type of the textbox on runtime. So, is there any way to implement client side validation with MVC UnobtrusiveJavaScript technique?

Appreciate your help.

Upvotes: 2

Views: 592

Answers (1)

TK-421
TK-421

Reputation: 427

When the data-type is set client side, set the value of a hidden field in your model. Your controller can validate the input based on which data type it gets from the model. If you have lots of text boxes on the page, this would get messy. I would go with Réda Mattar's suggestion then.

Upvotes: 1

Related Questions