通过加载MVC复选框,选中以禁用文本框 [英] MVC checkbox by loading, check to disable textbox

查看:93
本文介绍了通过加载MVC复选框,选中以禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁可以帮助我。

将数据加载到mvc视图时,我将加载复选框的值,但如果为true,我将需要禁用2个文本框字段。



代码是我的for循环的一部分

 @ 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>直到< / span >
@ Html.TextBoxFor(m = > m.Items [i] .EndIntervalTime, {0:HH:mm} {
Value = Model.Items [i]。可用吗? :Model.Items [i] .EndIntervalTime.ToString( HH:mm),
id = endTime + i
})
@ Html.CheckBoxFor(m = > m .Items [i] .Available, new {id = i,@ class = closedallday})





我试过,在textbox标签中与禁用一样,我使用值,但禁用将始终禁用文本框,即使没有值。那么......



<前lang =c#>已禁用= Model.Items [i]。可用? disabled





我需要一个真正有效的解决方案。



谢谢Dinand

解决方案

输入标签的禁用属性是罕见的无价值属性之一......这意味着它的价值是无关紧要的,只要提供它的属性将导致输入标签被禁用...

所有这些都具有相同的效果:

 <  输入   类型  =  text   名称  = 名称   已禁用    /  >  
< 输入 type = text 名称 = 名称 已禁用 = true / >
< 输入 type = text name = 名称 已禁用 = 已禁用 / >



你可以在你的文本框周围引入一个if语句,然后用一次禁用渲染一次,然后一次不用...


正如彼得谈到的那样......看起来像...... ...

  if (Model.Items [i] .Available)
{
@ Html.TextBoxFor(m = > m.Items [i] .StartIntervalTime, {0:HH:mm}
new {d isabled = disabled})
}
else
{
@ Html.TextBoxFor(m = > m.Items [i] .StartIntervalTime, {0:HH:mm}
}





没有心跳解决方案,双重代码......但是工作并解决了问题......感谢


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...


As Peter talked about...Gone look like .....

if(Model.Items[i].Available)
    {
     @Html.TextBoxFor(m => m.Items[i].StartIntervalTime, "{0:HH:mm}"
     , new { disabled="disabled" })
    }
    else
    {
    @Html.TextBoxFor(m => m.Items[i].StartIntervalTime, "{0:HH:mm}")
    }



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


这篇关于通过加载MVC复选框,选中以禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆