添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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 <span>untill </ span > @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 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... if (Model.Items[i].Available) @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
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •