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);
}