Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why disabled fields are not providing values on clicking submit in mvc3?

I have used Ajax.BeginForm / Html.BeginForm for a view which sends an object to the controller on clicking submit. There are some telerik controls which are disabled conditionally. On clicking submit, the object is unable to retrieve the already existing value in the control since it is disabled. Hence object is made with null values. Any help?

Im using jquery to disable these telerik controls on loading the page.

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 say how to remodify so that I can fetch the disabled field values?

like image 494
user1545987 Avatar asked Jan 21 '13 09:01

user1545987


2 Answers

That's how disabled inputs work. They never send the value to the server. You could use readonly instead if you want to prevent the user from modifying the value and yet send the old value to the server when the form is submitted.

like image 193
Darin Dimitrov Avatar answered Nov 04 '22 11:11

Darin Dimitrov


you can use something like this

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

before submit.

like image 45
Dhaval Pankhaniya Avatar answered Nov 04 '22 11:11

Dhaval Pankhaniya