首页 > 解决方案 > C# MVC DropDown Onchange 从视图包中删除下一个下拉列表的选定问题

问题描述

我正在尝试构建用户身份问题查看页面。一旦用户选择问题,我想从列表中删除问题以供下一个下拉列表,截至目前,我正在从视图包中选择问题,需要在下一个中删除选定的问题下拉框,请提供任何帮助。

@using (Html.BeginForm())
{
    <div class="loginPanel col-centered" style="width:700px">
        <section id="loginForm">
            <form action="/" class="loginForm" id="form0" method="post" role="form" autocomplete="off">
                <div class="form-horizontal" style="margin-left:auto;margin-right:auto;width:800px">
                    @Html.AntiForgeryToken()
                    <div class="form-horizontal">
                        <hr />
                        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                        <div class="form-group">
                            @Html.LabelFor(model => model.Question1, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.DropDownListFor(model => model.Question1, new SelectList(ViewBag.Questions, "value"), new { id = "Question1",, @class = "form-control", style = "width:500px; overflow:hidden" })

                                @Html.ValidationMessageFor(model => model.Question1)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Answer1, htmlAttributes: new { @class = "control-label col-md-2", }) })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.Answer1, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Answer1)
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Question2, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.DropDownListFor(model => model.Question2, new SelectList(ViewBag.Questions, "value"), new { id = "Question2", @class = "form-control", style = "width:500px; overflow:hidden" })
                                @Html.ValidationMessageFor(model => model.Question2)
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Answer2, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.Answer2, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Answer2)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Question3, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.DropDownListFor(model => model.Question3, new SelectList(ViewBag.Questions, "value"), new { id = "Question3", @class = "form-control", style = "width:500px; overflow:hidden" })
                                @Html.ValidationMessageFor(model => model.Question3, "", new { @class = "text-danger" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Answer3, htmlAttributes: new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.Answer3, new { htmlAttributes = new { @class = "form-control" } })
                                @Html.ValidationMessageFor(model => model.Answer3, "", new { @class = "text-danger" })
                            </div>
                        </div>
    <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <input type="submit" value="Submit" class="btn btn-lg btn-sharp btn-orange" />
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>

我知道我需要编写一个 javascript 代码来更新视图包,你能告诉我如何继续,因为我对这个 MVC 很陌生。

标签: javascriptasp.net-mvc

解决方案


推荐阅读