加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – MVC3有条件地禁用Html.TextBoxFor()

发布时间:2020-12-15 18:40:33 所属栏目:asp.Net 来源:网络整理
导读:我有一个C#.Net网络应用程序。在该应用程序中,我需要根据谁登录到系统来有条件地禁用Html.TextBoxFor控件(也就是Html.DropDownListFor控件)。我试过使用 @Html.TextBoxFor(model = model.ProposalName,new { @ViewBag.IsDisabled }) 其中@ ViewBag.IsDisabl
我有一个C#.Net网络应用程序。在该应用程序中,我需要根据谁登录到系统来有条件地禁用Html.TextBoxFor控件(也就是Html.DropDownListFor控件)。我试过使用
@Html.TextBoxFor(model => model.ProposalName,new { @ViewBag.IsDisabled })

其中@ ViewBag.IsDisabled在Controller中设置为String.Empty或“disabled”。但是,这将呈现为IsDisabled =“disabled”或IsDisabled =“”,因此控件未禁用。当我试过

@Html.TextBoxFor(model => model.ProposalName,new { @ViewBag.Disabled })

即使ViewBag.Disabled不包含任何文本,该控件始终被禁用。如何有条件地禁用Html.TextBoxFor()控件?

解决方法

尝试
@Html.TextBoxFor(model => model.ProposalName,ViewBag.Disabled ? (object)new { disabled="disabled" } : new {})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读