0

私はこのシナリオを持っています: 国を選択した後に「州」の div コンテンツをリロードする国の 1 つのドロップダウンリスト。

@Html.DropDownListFor(m => m.SelectedCountry, 
new SelectList(Model.Countries, "CountryId", "CountryName", Model.SelectedCountry))

<div id="states">
    @Html.Partial("Partial/States", Model)
</div>

<script type="text/javascript">
    $(document).ready(function() {

        $('#SelectedCountry').change(function() {

            if ($(this).val() !== "-1") {

                $.get('@Url.Action("LoadStates", "Controller")', 
                $('#form').serialize(), function(result) {
                    $('#states').html(result);
                });
            }
        }
    });
</script>

わかりました、それは完全に機能します。私の問題は、この PartialView をリロードすると、コンテンツの css スタイルが失われ、JS 参照で見つからないことです。選択したドロップダウン値に基づいてボタンを有効にするこの機能があります。

<script type="text/javascript">
    function canEnableButton() {
        //...
    }

    $('#SelectedCountry, #SelectedState').change(function() {
        canEnableButton();
    }
</script>

change()jQuery関数が動作する最初の読み込みページ。リロードすると、この機能が停止し、CSS スタイルが消えます。

誰が何ができるか知っていますか?ありがとう!

4

2 に答える 2