H All,
I had no experience in html/asp code.
Now, I'm trying to cascade 2 dropdown list. First of all, I prepare the Model
#region Category public class Category { [Key] public int CategoryID { get; set; } public string CategoryName { get; set; } } #endregion #region Category_Sub public class Category_Sub { [Key] public int SubCategoryID { get; set; } public int CategoryID { get; set; } public string SubCategoryName { get; set; } } #endregion
and for Controller
private readonly Project _project; public ProjectController(Project project) { _project = project; } // GET: /<controller>/ public IActionResult Index() { ViewData ["Message"] = "Project"; List<Category> lst_Category = _project.Category.FromSql ("[dbo].[Select_Category]").ToList ( ); lst_Category.Insert (0, new Category { CategoryID = 0, CategoryName = "--- Select ---" }); List<Category_Sub> lst_Category_Sub = _project.Category_Sub.FromSql("[dbo].[Select_Category_Sub]").ToList ( ); lst_Category_Sub.Insert (0, new Category_Sub { CategoryID = 0, SubCategoryName = "--- Select ---" }); ViewBag.Category = lst_Category; ViewBag.Category_Sub = lst_Category_Sub; return View(); }
and then, my questions are
- how to bind those data from 'Category' list and 'Category_Sub' list into @Html.DropDownList ? (controller to view)
- how to interact between each @HtmlDropDownList 'Category' and 'Category_Sub' ?
Thank in Adv
D