【发布时间】:2017-12-16 06:52:12
【问题描述】:
我有两个包含相同问题的下拉列表。 我必须从第一个下拉列表中“不显示”所选项目,反之亦然。如果我从第 1 个下拉菜单中选择了第 1 个问题,那么它在第 2 个下拉列表中将不可用。
下面是我的代码:
<div class="form-group">
@Html.DropDownListFor(m => m.ChallengeQuestion1, (SelectList)ViewBag.ChallengeQuestions, "-- Challenge Question 1 --", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ChallengeQuestion1)
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.ChallengeAnswer1, new { @class = "form-control", placeholder = "Answer" })
@Html.ValidationMessageFor(m => m.ChallengeAnswer1)
</div>
<div class="form-group">
@Html.DropDownListFor(m => m.ChallengeQuestion2, (SelectList)ViewBag.ChallengeQuestions, "-- Challenge Question 2 --", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ChallengeQuestion2)
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.ChallengeAnswer2, new { @class = "form-control", placeholder = "Answer" })
@Html.ValidationMessageFor(m => m.ChallengeAnswer2)
【问题讨论】:
-
这是我的一组问题 public IEnumerable
GetChallengeQuestions() { var questions = new List { new DropDownListItem { Name = "question1?" }, new DropDownListItem { Name = "question2?" },返回问题; } -
您需要使用javascript隐藏或禁用另一个
<select>元素中的选项
标签: c# asp.net-mvc html model-view-controller asp.net-mvc-5