部分视图中的下拉列表未扩展

时间:2013-11-25 15:03:48

标签: asp.net-mvc partial-views html-select

我正在开发一个asp.net MVC4网络应用程序,我需要显示StateList和CountryList。我有一个国家/地区的下拉列表,并且我正在通过ajax请求获得部分视图以显示相应的状态。部分视图具有各州的下拉列表。但一旦提出,各国的下拉列表就不会扩大。这是代码。

第一次观看:

<div class="row" style="margin-left: 12%">
           <div class="col-md-12 control-group">
                    <label class="col-md-4 control-label" style="margin-top :1%;"><b>Country:</b></label>
                <div class="col-md-4" style="">
                    @Html.DropDownListFor(Function(model) model.SelectedCountryId, Model.CountryList, New With {.style = "width:100px", .type = "text", .id = "country"})
                    @Html.ValidationMessageFor(Function(model) model.SelectedCountryId)
                </div>
            </div>
        </div>
<div id="stateDiv"></div>

脚本:

$(document).ready(function () {

    var rootUrl = $('#rootUrl').val();

    $('#country').change(function () {
        var countryCode = $(this).val();
        $.get(rootUrl + 'GetStateList', { countryCodeId: countryCode }, function (data) {
            $('#stateDiv').html(data);
        }, 'html');

        var isUSCAN = false;
        if ($(this).val() == 1 || $(this).val() == 2) {
            isUSCAN = true;
        }
        $('#stateSelect').toggle(isUSCAN);
        $('#stateText').toggle(!isUSCAN);

        var isCAN = $(this).val() == 2;
        $('#provinceLabel').toggle(isCAN);
        $('#stateLabel').toggle(!isCAN);

    }).change();
});

控制器:

Function GetStateList(countryCodeId As Integer) As ActionResult
    Return PartialView("PartialStateList", Defendant)
End Function

PartialStateList查看

<div class="row" style="margin-left: 12%">
           <div class="col-md-12 control-group">
                    <label id="stateLabel" class="col-md-4 control-label" style="margin-top :1%;"><b>State:</b></label>
                    <label id="provinceLabel" class="col-md-4 control-label" style="margin-top :1%;"><b>Province:</b></label>
                <div class="col-md-4" style="">
                    @Html.DropDownListFor(Function(model) model.SelectedStateId, Model.StateList, New With {.style = "width:100px", .type = "text", .id = "stateSelect"})
                    @Html.TextBoxFor(Function(model) model.SelectedStateId, New With {.style = "width:100px", .value = "", .type = "text", .id = "stateText"})
                    @Html.ValidationMessageFor(Function(model) model.SelectedStateId)
                </div>
            </div>
        </div>

我在浏览器中检查时呈现的html具有完整的状态列表,但是当我单击下拉列表时,它不会展开并显示列表。如果我遗失了某些东西,请告诉我。

0 个答案:

没有答案
相关问题