下拉列表不是Modal中的刷新数据

时间:2018-05-26 12:50:36

标签: jquery asp.net-mvc twitter-bootstrap

我使用bootstrap模式删除包含下拉列表的数据。 下拉列表的值没有变化,就像我在下拉列表中有三个值 显示模态时的A,B,C下拉列表显示A,如果我选择B并关闭模态并再次打开某些其他数据,它仍然显示B已选中。

模态:

<div id="detail">
    <div class="modal fade" id="detailUnit"  role="dialog" aria-labelledby="detailUnitLabel" data-backdrop="static" data-keyboard="false" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="detailUnitLabel">Add Unit</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                @using (Html.BeginForm())
                {
                    <form id="createPackageForm">
                        <div class="modal-body">
                            <div class="row flex-center">
                                <div class="col-sm-12 col-md-12">
                                    <div class="card">
                                        <div class="card-body col-md-12">
                                            <fieldset id="fld">
                                                @Html.HiddenFor(model => model.Unit.UNIT_PAKE_CODE, new { @id = "hdnPkgView"})
                                                @Html.HiddenFor(model => model.Unit.UNIT_IP_FLAG,   new { @id = "hdnIpFlagVIew" })
                                                <div class="form row">
                                                    <div class="col-md-8 md-form">
                                                        @Html.DropDownListFor(model => model.Unit.UNIT_PAKE_CODE, new SelectList(ViewBag.PkgSelect, "Value", "Text") , new { @class = " col-md-12 mdb-select colorful-select dropdown-primary",  @id = "detailddlPackage"})
                                                        @Html.LabelFor(model => model.Unit.UNIT_PAKE_CODE)
                                                        @Html.ValidationMessageFor(model => model.Unit.UNIT_PAKE_CODE, "", new { @class = "text-danger" })
                                                    </div>
                                                </div>
                                                <div class="form row">
                                                    <div class="col-md-8 md-form">
                                                        @Html.LabelFor(model => model.Unit.UNIT_CODE)
                                                        @Html.TextBoxFor(model => model.Unit.UNIT_CODE, new { @readonly = true, @class = "form-control col-md-12", @MaxLength = 2, @id = "detailtxtAddUnitCode", @placeholder = "Unit Code", @onkeypress = "return IsNumeric(event)" })
                                                        @Html.ValidationMessageFor(model => model.Unit.UNIT_CODE, "", new { @class = "text-danger" })
                                                    </div>
                                                </div>
                                                <div class="form row">
                                                    <div class="col-md-8 md-form">
                                                        @Html.LabelFor(model => model.Unit.UNIT_NAME)
                                                        @Html.TextBoxFor(model => model.Unit.UNIT_NAME, new { @readonly = true, @class = "form-control col-md-12", @MaxLength = 50, @id = "detailtxtAddUnitName", @placeholder = "Unit Name", @type = "text" })
                                                        @Html.ValidationMessageFor(model => model.Unit.UNIT_NAME, "", new { @class = "text-danger" })
                                                    </div>
                                                </div>
                                                <div class="form row">
                                                    <div class="col-md-8 md-form">
                                                        @Html.DropDownListFor(model => model.Unit.UNIT_IP_FLAG, Model.Unit.StatusList, new { @class = "col-md-12 mdb-select colorful-select dropdown-primary", @searchable = "Search here...", @id = "detailddlStatus", @disabled = "disabled" })
                                                        @Html.LabelFor(model => model.Unit.UNIT_IP_FLAG)
                                                        @Html.ValidationMessageFor(model => model.Unit.UNIT_IP_FLAG, "", new { @class = "text-danger" })
                                                    </div>
                                                </div>
                                                <div class="form row">
                                                    <div class="col-md-6 md-form">
                                                        @Html.LabelFor(model => model.Unit.UNIT_IP_FROM)
                                                        @Html.TextBoxFor(model => model.Unit.UNIT_IP_FROM, new { @readonly = true, @class = "form-control", @MaxLength = 15, @id = "detailtxtAddUnitIPFrom", @placeholder = "IP Address", @type = "text" })
                                                        @Html.ValidationMessageFor(model => model.Unit.UNIT_IP_FROM, "", new { @class = "text-danger" })
                                                    </div>
                                                    <div class="col-md-6 md-form">
                                                        @Html.LabelFor(model => model.Unit.UNIT_IP_TO)
                                                        @Html.TextBoxFor(model => model.Unit.UNIT_IP_TO, new { @readonly = true, @class = "form-control ", @MaxLength = 15, @id = "detailtxtAddUnitIPTo", @placeholder = "IP Address", @type = "text" })
                                                        @Html.ValidationMessageFor(model => model.Unit.UNIT_IP_TO, "", new { @class = "text-danger" })
                                                    </div>
                                                </div>
                                            </fieldset>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group modal-footer">
                            <button type="submit" id="btnView" class="btn btn-primary"data-dismiss="modal"> Ok</button>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</div>

脚本:

<script type="text/javascript">
    $("body").on("click", ".detail", function () {
        var row = $(this).closest("tr");
        var pkg = row.find("td").eq(1).html();
        var unit = row.find("td").eq(2).html();
        $('#detailUnit').removeData();
        $('#detailUnit').modal('toggle');
        getUnitDetail(pkg, unit);
        return false;
    });
    $.ajaxSetup({
        cache:false
    })
    function ValidateIPaddress(ipaddress) {
        if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
            return (true)
        }
        swal('Oops...', 'You have entered an invalid IP address!', 'error');
        return (false)
    }

    function getUnitDetail(pkgCode,unitCode) {
        $.ajax({
            url: "/ManageUnit/getUnitDetail",
            type: "POST",
            datatype: "JSON",
            data:
              {
                  PackageId: pkgCode,
                  UnitId: unitCode
              },
            success: function (response) {
                $("#detailtxtAddUnitCode").val(Number(unitCode));
                $("#detailtxtAddUnitName").val(response[0]);
                $("#detailddlStatus").val(Number(response[1]));
                $("#detailtxtAddUnitIPFrom").val(response[2]);
                $("#detailtxtAddUnitIPTo").val(response[3]);
                $("#detailddlPackage option[value=2]").attr('selected', true);
                $('#detailddlPackage'),val(Number(pkgCode));

            },
            error: function (result) {
                error = 1;
                //   swal('Oops...', result, 'error');
            }
        });
    }
</script>

0 个答案:

没有答案