c# - @Html.Dropdownlist C# MVC 4 当 bool = true 时显示 div

标签 c# javascript css asp.net-mvc razor

我在彼此下面有很多 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/

相关文章:

c# - 如何将数组转换为字典

javascript - Jquery 脚本可以在 JSfiddle 中运行,但不能在 html 页面上运行

javascript - jQuery 可选择序列化为数组

css - SVG 或 HTML 中像素完美一致的文本宽度

css - <div style ="height:100%"> 由于上层菜单的高度大于页面。如何解决这个问题?

c# - 变量范围 : Instantiation Inside or Outside Loop

c# - 如何使用 Roslyn 将 C# 关键字替换为字符串替代项?

javascript - 如何用另一个变量的值命名变量? JS

html - 如何从 Bootstrap 表响应中删除边框?

c# - excel以编程方式获取范围