我正在构建一个MVC 4应用程序,如果输入了另一个TextBoxFor,我正在尝试禁用 一个TextBoxFor(或添加一些文本)。试图使用 switch-case 语句,但到目前为止没有运气。因为我必须添加文本/禁用其他TextBoxFor这必须在运行时运行。
创建视图代码的一部分:
<div class="editor-label2">
@Html.LabelFor(model => model.First)
</div>
div class="editor-field2">
@Html.TextBoxFor(model => model.First, new { @id = "id1"} )
@Html.ValidationMessageFor(model => model.First)
</div>
<div class="editor-label3">
@Html.LabelFor(model => model.Second)
</div>
<div class="editor-field3">
@Html.TextBoxFor(model => model.Second, new { @id = "id2"} )
@Html.ValidationMessageFor(model => model.Second)
</div>
和这个:
@{
switch (id1)
{
case 1:
<text> text1 </text>
break;
case 2:
<text> text2 </text>
break;
default:
<text> text </text>
break;
}
}