Hi!
I have the following setup:
CsHtml:
<div class="row mt-3">
<div class="col-lg-4">
@(Html.Kendo().DropDownListFor(m => m.CategoryHeadId)
.Size(ComponentSize.Medium)
.Rounded(Rounded.Medium)
.FillMode(FillMode.Solid)
.OptionLabel("Select head category...")
.HtmlAttributes(new { style = "width: 100%" })
.DataTextField("Name")
.DataValueField("Id")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetLookupCategoriesHead", "Api");
});
})
)
</div>
<div class="col-lg-4">
@(Html.Kendo().DropDownListFor(m => m.CategoryMainId)
.Size(ComponentSize.Medium)
.Rounded(Rounded.Medium)
.FillMode(FillMode.Solid)
.OptionLabel("Select main category...")
.HtmlAttributes(new { style = "width: 100%" })
.DataTextField("Name")
.DataValueField("Id")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetLookupCategoriesMain", "Api")
.Data("filterMainCategories");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("CategoryHeadId")
)
</div>
<div class="col-lg-4">
@(Html.Kendo().DropDownListFor(m => m.CategorySubId)
.Size(ComponentSize.Medium)
.Rounded(Rounded.Medium)
.FillMode(FillMode.Solid)
.OptionLabel("Select sub-category...")
.HtmlAttributes(new { style = "width: 100%" })
.DataTextField("Name")
.DataValueField("Id")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetLookupCategoriesSub", "Api")
.Data("filterSubCategories");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("CategoryMainId")
)
</div>
</div>
Script:
@section Scripts {
<script>
function filterMainCategories() {
return {
headId: $("#CategoryHeadId").val()
};
}
function filterSubCategories() {
return {
headId: $("#CategoryHeadId").val(),
mainId: $("#CategoryMainId").val()
};
}
</script>
}
Controller:
public async Task<JsonResult> GetLookupCategoriesHead()
{
var result = await serviceLookUps.GetAllCategoriesHeadAsync();
return new JsonResult(result);
}
public async Task<JsonResult> GetLookupCategoriesMain(int headId)
{
var result = await serviceLookUps.GetAllCategoriesMainAsync(headId);
return new JsonResult(result);
}
public async Task<JsonResult> GetLookupCategoriesSub(int headId, int mainId)
{
var result = await serviceLookUps.GetAllCategoriesSubAsync(headId, mainId);
return new JsonResult(result);
}
Model:
[DebuggerDisplay($"{nameof(Id)}: {{{nameof(Id)},nq}}, {nameof(Name)}: {{{nameof(Name)}}}, {nameof(Active)}: {{{nameof(Active)}}}")]
public class LookupCategoryHeadModel
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public bool Active { get; set; }
}
[DebuggerDisplay($"{nameof(Id)}: {{{nameof(Id)},nq}}, {nameof(Name)}: {{{nameof(Name)}}}, {nameof(Active)}: {{{nameof(Active)}}}")]
public class LookupCategoryMainModel
{
public int Id { get; set; }
public int HeadId { get; set; }
public string Name { get; set; } = string.Empty;
public bool Active { get; set; }
}
[DebuggerDisplay($"{nameof(Id)}: {{{nameof(Id)},nq}}, {nameof(Name)}: {{{nameof(Name)}}}, {nameof(Active)}: {{{nameof(Active)}}}")]
public class LookupCategorySubModel
{
public int Id { get; set; }
public int HeadId { get; set; }
public int MainId { get; set; }
public string Name { get; set; } = string.Empty;
public bool Active { get; set; }
}
I have tested the API methods separately through tests and ensured they are returning values. The only issue is, when I make a selection in the second dropdown, on the API, the second parameter is received as 0 instead of a correct selected value. This doesn't cause any console errors so the UI continues to work. I can cascade from dropdown one to dropdown two but dropdown two sends a 0 for mainId from its filtering operation in filterSubCategories()
Hold up!
There is an error in the data coming from my staging API. THis is not an issue.