In my MVC3 app I have two dropdowns "Category" and "SubCategory" in a view which are from two different models. The view itself belongs to a third model. I am using NHibernate for ORM.
My question is how do I cascade the two drop downs. The SubCategory dropdown should display values depending on the value selected in Category dropdown. The"Category" dropdown retrieves value from "Categories" model and "SubCategory" dropdown retrieves value from "SubCategories" model. These two dropdowns are displayed in a view that belongs to another model "Expenses".
Please view this snippet of code for further information. Expense View has following dropdowns:
@using (Html.BeginForm()) {
<div class="editor-field">
@Html.DropDownListFor(model => model.CategoryId.CategoryName, new SelectList(new MyExpense.Persistence.Repositories.CategoriesRepository().GetCategoryName()))
@Html.ValidationMessageFor(model => model.CategoryId.CategoryName)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.SubCategoryId.SubCategoryName, new SelectList(new MyExpense.Persistence.Repositories.SubCategoriesRepository().GetSubCategoryName()))
@Html.ValidationMessageFor(model => model.SubCategoryId.SubCategoryName)
</div>
}
CategoriesRepository and SubCategoriesRepository are classes that contains methods that retrieve Categories and SuCategories from the database.
Any help on this is much appreciated.