MonoRail - Select parent category from one dropdown, show child category dropdown
Posted
by Justin
on Stack Overflow
See other posts from Stack Overflow
or by Justin
Published on 2010-05-27T01:06:55Z
Indexed on
2010/05/27
1:11 UTC
Read the original article
Hit count: 439
monorail
Hey,
I'm new to MonoRail and am trying to figure out how to have it so that I can select a parent category in a dropdown then have it show a second dropdown with the categories that are children of the parent.
If I were using what I'm used to, ASP.NET MVC, I would have a javascript function that would be called onchange of the first dropdown and would make an ajax call to a controller method (passing in the selected parent category id) that would grab all child categories of that parent category and return them in JSON. Then in the callback javascript function I would eval the JSON and populate the second dropdown with the child categories.
How would I do this using MonoRail/jQuery? Here's the code I have so far:
$FormHelper.Select("business.category.id", $categories, "%{value='id', text='name', firstoption='Select a Category'}")
$FormHelper.Select("business.category.id", $childCategories, "%{value='id', text='name', firstoption='Select a Sub-Category'}")
Then in BusinessController.cs:
private void AddDataToModels()
{
PropertyBag["categories"] = CategoryRepository.GetParentCategories();
PropertyBag["childCategories"] = CategoryRepository.GetChildCategories(1);
}
Thanks for any input on how to approach this!
Justin
© Stack Overflow or respective owner