I tried to implement the example here
https://www.c-sharpcorner.com/article/creating-simple-cascading-dropdownlist-in-asp-net-core-mvc-with-new-tag-helpers/
into my Razor page project but the second dropdown doesn't get any data. What I did is
View Page including script
- class="col-2">
- ="PTWReviewD.Category" class="form-control badge-primary">PTW Review Category
- ="PTWReviewD.Category" class="form-control border-warning" asp-items="Model.PTWRCList">
- >--Select PTW Review Category--
- for="PTWReviewD.Category" class="text-danger">
- class="col-2">
- ="PTWReviewD.SubCategory" class="form-control badge-primary">PTW Review Subcategory
- ="PTWReviewD.SubCategory" class="form-control border-warning" asp-items="@(new SelectList(string.Empty, "RSubCategoryID", "RSubCategoryS"))">
- >--Select PTW Review Subcategory--
- for="PTWReviewD.SubCategory" class="text-danger">
- @Html.AntiForgeryToken()
- @section scripts{
- }
- public async Task
OnGetAsync( int ptwNoId) - {
- //PTWRCategory
- PTWRCList = await _context.PTWRCategories.Select(a =>
- new SelectListItem
- {
- Value = a.RCategoryID.ToString(),
- Text = a.RCategoryS
- }).ToListAsync();
- return Page();
- }
- public async Task
OnGetSubCategoriesAsync( int RCategoryID) - {
- PTWRSCList = await _context.PTWRSubCategories.Where(a => a.RCategoryID == RCategoryID).Select(a =>
- new SelectListItem
- {
- Value = a.RSubCategoryID.ToString(),
- Text = a.RSubCategoryS
- }).ToListAsync();
- return new JsonResult(new SelectList(PTWRSCList, "RSubCategoryID", "RSubCategoryS"));
- }

Marius VasilePosted Dec 19, 2020, 3:29 PM
Marius VasilePosted Dec 19, 2020, 2:41 PM
Marius VasilePosted Dec 19, 2020, 12:13 AM