ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
MVC4 Razor Linked Cascading Dropdown List example
Title:
B
I
{code}
?
Do you have sample code for cascading drop down lists using Razor syntax? Using Entity Framework 5 and .Net 4.0
Save Changes
Cancel
Mistral
asked at 25 Jan 2012
Answers
B
I
{code}
?
you need to declare and bind them using.Parent, like this: Parent Category: @(Html.Awe().AjaxDropdownFor(o => o.ParentCategory) .Url(Url.Action("CategoryGetItems"))) Child Meal: @(Html.Awe().AjaxDropdownFor(o => o.ChildMeal) .Url(Url.Action("MealGetItems")) .Parent(o => o.ParentCategory, "category")) and the controller would be something like this: public ActionResult CategoryGetItems() { return Json(Db.Categories.Select(o => new KeyContent(o.Id, o.Name))); } public ActionResult MealGetItems(int? cateogry) { return Json(Db.Meals.Where(o => o.Category.Id == category) .Select(o => new KeyContent(o.Id, o.Name))); } you can see the cascading dropdowns demo here : http://demo.aspnetawesome.com (you can download this demo) another approach is using Client data loading, see here: http://demo.aspnetawesome.com/ClientDataLoadingDemo or have a look at this multilevel cascading demo http://demo.aspnetawesome.com/MultipleLevelCascadingDemo where you'll see the power and ease of using cascading in Awesome MVC lib
Save Changes
Cancel
Omu
answered at 26 Jan 2012
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK