模态窗口关闭时重置DropDownListing

时间:2016-07-07 20:08:10

标签: asp.net razor

我有一个弹出的模态联系我们窗口,下拉列表中选择一个类别。当我通过取消按钮或x按钮关闭模态时,我试图想出一种重置所选项目的方法。到目前为止,我已经想出如何做到这一点的唯一方法是在单击任一按钮时快速刷新页面(请参阅底部附近的CloseAndRefresh函数)。这并不理想,因为如果某人输入了数据而未提交数据,则刷新将全部删除。如果没有刷新,是否有更简单的方法来实现这一目标?

以下是我的模态按钮的代码

@Html.ModalButton( string.Empty, Rxcs.Contact + " " + Rxcs.Support, "none", "HelpContactSupport" )
<div id="page-contact-form">
    <a href="#" title="Close" class="close" onclick="CloseAndRefresh()">X</a>
    @using (Html.BeginForm( "ContactHelp", "emails", FormMethod.Post ))
    {
        <div class="row">

            @if (Request.IsAuthenticated && Session["PersonID"] != null)
            {
                <input type="hidden" name="address" value="@ViewContext.GetContext().people.Find(Session["PersonID"]).Email" />
            }
            else
            {
                <label for="address" class="medium-2 columns text-right">Email Address:</label>
                <div class="medium-10 columns">
                    <input type="text" name="address" id="address" />
                </div>
            }
            <div class="medium-2 hide-for-small columns">&nbsp;</div>
            <div class="medium-10 columns">
                <p>@Rxcs.What_is_your_question</p>
            </div>
            <label class="medium-2 columns text-right" for="contactCat">
                @Rxcs.Category
            </label>
            <div class="medium-10 columns" id="selectParent">
                @Html.DropDownListing( "contactCat", new SelectList( ViewContext.GetContext().contact_category, "ID", "CategoryNameEnglish" ) )
            </div>

            <div id="bodyParent">
                <input type="hidden" name="Subject" value="Contact Help on Page: @Request.Url.AbsoluteUri" class="col-md-10" />
                <label class="medium-2 columns text-right" for="body">@Rxcs.Body.Replace( "English", "" ).Replace( "anglais", "" )</label>
                <div class="medium-10 columns">
                    <textarea rows="10" cols="100" name="body" id="body"></textarea>
                </div>
                <input type="submit" value="@Rxcs.Send" class="button float-right" onclick="$('#contactCat').next().children().first().css('border', '1px solid #f00');return $('#contactCat').val() != '';" />
            </div>
            <a class="button inline float-left" onclick="CloseAndRefresh()">@Rxcs.Cancel</a>

            <script>
                function CloseAndRefresh() {
                    location.href = '#';
                    javascript: history.go(0);
                }
            </script>

            <br />
        </div>
    }
</div>
@Html.ModalButtonEnd()  

1 个答案:

答案 0 :(得分:0)

我是通过清除下拉列表选项然后将其分配给第一个文本来完成此操作这是一个代码段可能会帮助您

dropdownname.ClearSelection();
dropdownname.Items.FindByText(Your Text).Selected = true;