Click here to Skip to main content
15,790,884 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Who can help me.
When loading data to a mvc view, i'll load the value of the checkbox, but if true, i'll need to disable 2 textbox fields.

Code is a piece of my for loop
@Html.TextBoxFor(m => m.Items[i].StartIntervalTime, "{0:HH:mm}", new {
                Value = Model.Items[i].Available ? "" : Model.Items[i].StartIntervalTime.ToString("HH:mm"),
                id = "startTime" + i
@Html.TextBoxFor(m => m.Items[i].EndIntervalTime, "{0:HH:mm}", new {
                Value = Model.Items[i].Available ? "" : Model.Items[i].EndIntervalTime.ToString("HH:mm"),
                id = "endTime" + i
@Html.CheckBoxFor(m => m.Items[i].Available, new { id = i, @class = "closedallday" })

I've tried, in the textbox tag, with "disabled" like i did with "value", but disabled will always disables the textbox even without a value. So..

Disabled = Model.Items[i].Available ? "disabled" : "",

I need a real working solution.

Thank you Dinand
Updated 23-Dec-14 22:01pm

Input tag's disabled attribute is one of the rare 'valueless' attributes...It means that it's value is irrelevant, as long as the attribute presented it will render the input tag disabled...
All these have the same effect:
<input type="text" name="name" disabled />
<input type="text" name="name" disabled="true" />
<input type="text" name="name" disabled="disabled" />

You may introduce an if statement around your textbox and render once with disabled and once without...
Share this answer
Dinand.dotnet 25-Dec-14 3:07am    
Thanx Peter, Yes I did create two textboxes, one with and one without disable... For a programmer a painfull look, having 2 time almost the same code for the same target...
As Peter talked about...Gone look like .....
     @Html.TextBoxFor(m => m.Items[i].StartIntervalTime, "{0:HH:mm}"
     , new { disabled="disabled" })
    @Html.TextBoxFor(m => m.Items[i].StartIntervalTime, "{0:HH:mm}")

No heartbeating solution, double code... but working and solves the problem..Thanx
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900