This is a migrated thread and some comments may be shown as answers.

Can't get Cascading DropDownLists to work

1 Answer 45 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 11 Oct 2012, 02:28 PM
My Banks dropdownlist is populated, but once I select a bank, it never fires the JsonResult of the Accounts dropdown.  I feel like I'm doing exactly what the demos are, but I must be missing something.  Any Help would be greatly appreciated.

My Popup Template.cshtml:

<table id="table">
    <tr>
        <td>
            Bank
        </td>
        <td>
            @(Html.Kendo().DropDownList()
          .Name("banks")
                  .OptionLabel("-- Select Item --")
          .DataTextField("BankName")
          .DataValueField("BankId")
          .DataSource(source => {
               source.Read(read =>
                               {
                                   read.Action("GetCascadeBanks", "Home");
                               });
          })

                  ) 
        </td>
    </tr>
    <tr>
        <td>
            Account
        </td>
        <td>
            <script>
                function filterAccounts() {
                    return {
                        banks: $("#banks").val()
                    };
                }
            </script>
           
            @(Html.Kendo().DropDownList()
          .Name("accounts")
                  .OptionLabel("-- Select Item --")
          .DataTextField("AccountName")
          .DataValueField("AccountID")
          .DataSource(source => {
              source.Read(read =>
              {
                  read.Action("GetCascadeAccounts", "Home")
                      .Data("filterAccounts");
              })
              .ServerFiltering(true);
          })
          .Enable(false)
          .AutoBind(false)
          .CascadeFrom("banks")
                  )
        </td>
    </tr>
</table>


HomeController:

public JsonResult GetCascadeBanks()
        {
            var ortbanks = from bank in db.ORTBanks
                           orderby bank.BankName

                           select new TreasuryCreateItem()
                                      {
                                          BankID = bank.BankID,
                                          BankName = bank.BankName,
                                      };

            return Json(ortbanks, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetCascadeAccounts(int banks)
        {
            var ortaccounts = from account in db.ORTAccounts
                              where account.AccountName != string.Empty
                           orderby account.AccountName

                           select new TreasuryCreateItem()
                           {
                               AccountID = account.AccountID,
                               AccountName = account.AccountName,
                           };

            var accountsInBank = from p in ortaccounts where p.BankID == banks select p;

            return Json(accountsInBank, JsonRequestBehavior.AllowGet);
        }



1 Answer, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 11 Oct 2012, 02:44 PM
I guess I just needed to post this.  My first problem is that I had BankId and needed BankID.  Now I have to look at my JsonResult.
Tags
DropDownList
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Share this question
or