我在彼此下面有很多 div,当我选择了一个值并且为真时,我想显示另一个 div。我知道我可以用 javascript 做这个,但我如何用 Razor 做呢?
这是我的一些代码,
<div id="Attend">
@Html.DropDownListFor(model => model.AttendWedding, new[]
{
new SelectListItem() {Text = "Yes, I'll be there", Value = bool.TrueString },
new SelectListItem() {Text ="No, I can't come", Value = bool.FalseString }
}, "Choose an option")
</div>
<div id="Hotel">
@Html.DropDownListFor(model => model.WillStayAtHotel, new[]
{
new SelectListItem() {Text = "Yes, I will stay at the hotel", Value = bool.TrueString},
new SelectListItem() {Text ="No, I won't stay at the hotel", Value = bool.FalseString }
}, "Choose an option")
</div>
<div id="Nights">
@Html.LabelFor(model => model.HowManyNights, "How Many Nights?:", new { @class = "dob" })
1
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
2
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
3
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
4
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
<br />
5
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
6
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
7
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
8
@Html.RadioButtonFor(model => model.HowManyNights, new { style = "width: 1000px; height:50px; overflow:hidden;" })
</div>
<div id="When">
@Html.TextBoxFor(model => model.StartDate, "{mm/dd/yyyy}",new {@class="datepicker"})
@Html.TextBoxFor(model => model.EndDate, "{mm/dd/yyyy}", new { @class = "datepicker" })
</div>
因此,当人们单击“我会参加”时,“酒店”div 应该显示等等。
感谢所有帮助。
最佳答案
您必须使用 javascript 才能实现此功能,因为它位于客户端。 Razor 由服务器解析...当然有可能在有人将表单发布到服务器后发送表单并在页面重新加载后显示更多字段。但这几天没有任何意义。 ;)
关于c# - @Html.Dropdownlist C# MVC 4 当 bool = true 时显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25338529/