tags:

views:

73

answers:

1

I am working on MVC with C#.

I have 2 radio buttons. On selecting first radio button, a textbox will be shown which allows to enter date values. <%= Html.TextBox("ReceivedDate")%>

on selecting the second radio button, the textbox gets hidden.

For the first time, when i select first radio button and entered date and clicked Next to navigate to next page and came back to this page again and clicked second radio button and clicked Next to continue and again i came back to this page and without changing any option click continue, its not allowing to navigate and shows an error.

      A value is required.

Which means the ModelState validating the hidden controls also.

Please suggest how to control it

A: 

Instead of hiding it remove the element from the DOM and reinsert it if the first item is selected again. Another way would be to change the name of the input control to something else (a key not present in your model data) when the first item is not selected.

Validating hidden input types is a good thing, i often use them to synchronize data from complex controls (like a treeview with checkboxes). An input type with a hidden css style doesn't make it not submit with the form it belongs too.

Martijn Laarman
Changing the name of the control really worked. Thanks.
Prasad