0

Jqueryでカスケードドロップダウンリストを作成しましたが、うまく機能しますが、2番目のドロップダウンが変更されたときにフォームを送信する際に問題が発生しました。これが私のコードです。

$("#Bank").change(function () {
        var bankId = $(this).val();
        $.ajax("/App/BankBranch/ByBank", {
            data: { "id": bankId },
            type: "get", contentType: "application/json",
            success: function (result) {
                var options = $("#id");
                options.html("");
                $.each(result, function () {

                    options.append($("<option />").val(this.Id).text(this.Name));

                });

            }

        });

    }).trigger('change'); //to make the event run on initialization for default value



        $('#id').change(function() {
            this.form.submit();

    });

フォームは、ドロップダウンから値を選択したときにのみ送信されますが、最初のドロップダウンが2番目のデータで満たされると、フォームは送信されません。

追加された HTML の更新

<h2>@ViewBag.Title</h2>

            <h4>Seleccione Sucursal</h4>
            @using (Html.BeginForm(null, null, FormMethod.Get))
                {
                    <div class="pull-left">
                        @Html.Label("Banco")
                        @{Html.RenderAction("GetAllBanks", "Bank", new { ControlName = "Bank" });}
                      &nbsp;
                   </div>

                <div class="pull-left">
                    @Html.Label("Sucursal")
                    @Html.DropDownList("id", Enumerable.Empty<SelectListItem>(),null ,new {name="id", @class="input-medium"})
                 </div>
            }
4

1 に答える 1

0
 $('#id').change(function() {
        this.form.submit();; //double semi-colon here, remove and it should be fine

 });
于 2012-10-17T15:05:07.937 に答える