我是 MonoRail 的新手,我想弄清楚如何拥有它,以便我可以在下拉列表中选择一个父类别,然后让它显示第二个下拉列表,其中包含父类别的子类别。
如果我使用的是我习惯的 ASP.NET MVC,我将有一个 javascript 函数,该函数将被称为第一个下拉列表的 onchange,并对控制器方法进行 ajax 调用(传入选定的父类别 ID)这将获取该父类别的所有子类别并以 JSON 格式返回它们。然后在回调 javascript 函数中,我将评估 JSON 并使用子类别填充第二个下拉列表。
我将如何使用 MonoRail/jQuery 做到这一点?这是我到目前为止的代码:
$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'}")
然后在 BusinessController.cs 中:
private void AddDataToModels()
{
PropertyBag["categories"] = CategoryRepository.GetParentCategories();
PropertyBag["childCategories"] = CategoryRepository.GetChildCategories(1);
}
感谢您提供有关如何解决此问题的任何意见!
贾斯汀