0

I have a DropDown and a Search button on my View. When user selects year from the DropDown and clicks Search, I am showing a list.

This list has five columns and the first one is a CheckBox. The other columns have TextBoxes. There is also a Save button. User checks few CheckBoxes and clicks Save. The column values of the selected rows are saved in the database and the list reloads.

At this time, when the list reloads, I want to disable some of the rows. These are those rows which were previously checked and saved.

I want to know how to make Checkbox and Textbox disabled from Controller.

Is there any way to do this from C# code in controller without using jQuery or javascript.

I am using Razor Engine.

RKh
  • 13,818
  • 46
  • 152
  • 265
  • Not sure what you are trying to achieve with this. Unless your generating a hidden inputs for an indexer in each row, then disabling inputs in a collection will cause binding to fail when you post back a second time. –  May 27 '15 at 23:36
  • @StephenMuecke How to put hidden inputs for each row? – RKh May 28 '15 at 04:39
  • Without seeing you model I cant give you the actual code, but [this answer](http://stackoverflow.com/questions/29837547/set-class-validation-for-dynamic-textbox-in-a-table/29838689#29838689) should help. Note the `` line. It allows non-zero based, non consecutive indexers to post back and be bound to a collection. –  May 28 '15 at 05:02

1 Answers1

0

Your view would do the work of rendering the disabled flag on the textbox when the checkbox has a certain value for each row. You can't really do that work from the controller.

Something like this:

@foreach ()
{
    <tr>
        <td>
            <input type="text" @(checkboxIsChecked ? "disabled=\"disabled\"" : "") />
        </td>
    </tr>
}
Marc Johnston
  • 1,276
  • 1
  • 7
  • 16