Why don't disabled fields provide a value when submit is submitted in mvc3?

I used Ajax.BeginForm / Html.BeginForm for a view that sends an object to the controller when submit is clicked. There are some telerik controls that are conditionally disabled. When you click the Submit button, the object cannot receive an existing value in the control, since it is disabled. Therefore, the object is created with zero values. Any help?

I am using jquery to disable these telerik controls when the page loads.

Change.setDropDownValues = function () { if (condition) { $("#A").data('tDropDownList').enabled = false; $("#A").data('tDropDownList').disable(); } } else if (condition) { $('#Pop').attr('disabled', 'disabled'); //text box $('#ShortDesc').attr('disabled', 'disabled'); //textarea $('#LongDesc').attr('disabled', 'disabled'); //text area $('#Cont').attr('disabled', 'disabled'); //text box $('#iDate').attr('disabled', 'disabled'); //datepicker division $('#C').data('tDropDownList').enabled = false; //drop down list $('#C').data('tDropDownList').disable(); } }; 

Can anyone tell me how to redo so that I can get the values โ€‹โ€‹of the disabled field?

+4
source share
2 answers

How disabled inputs work. They never send the value to the server. You can use readonly instead if you want the user to not change the value and still send the old value to the server when submitting the form.

+13
source

you can use something like this

 $(":disabled", $('#yourform')).removeAttr("disabled"); 

before sending.

+1
source

All Articles