Parent
<div class="elabel">Parent Category:</div><% ParentCategory.AjaxDropdown() .Url(Page.Url().Action("GetCategories", "Data")); %><awe:Ocon runat="server" ID="ParentCategory" /><div class="elabel">Child Meal:</div><% ChildMeal.AjaxDropdown() .Parent(ParentCategory.ClientID, "categories") .Url(Page.Url().Action("GetMeals", "Data")); %><awe:Ocon runat="server" ID="ChildMeal" />
public ActionResult GetCategories(){ return Json(Db.Categories.Select(o => new KeyContent(o.Id, o.Name)));}public ActionResult GetMeals(int[] categories){ categories = categories ?? new int[] { }; var items = Db.Meals.Where(o => categories.Contains(o.Category.Id)) .Select(o => new KeyContent(o.Id, o.Name)); return Json(items);}
<% Category1.AjaxRadioList().Url(Page.Url().Action("GetCategories", "Data")); %><awe:Ocon runat="server" ID="Category1" />+<% Categories.AjaxCheckboxList().Url(Page.Url().Action("GetCategories", "Data")); %><awe:Ocon runat="server" ID="Categories" />+<% TxtMealName.TextBox().Placeholder("where name contains").CssClass("searchtxt"); %><awe:Ocon runat="server" ID="TxtMealName" />=<% ChildOfManyMeal.AjaxDropdown() .Controller<MealBoundToManyController>() .Parent(Category1.ClientID) .Parent(Categories.ClientID) .Parent(TxtMealName.ClientID, "mealName"); %><awe:Ocon runat="server" ID="ChildOfManyMeal" />=<% ChildOfManyMealRadioList.AjaxRadioList() .Controller<MealBoundToManyController>() .Parent(Category1.ClientID) .Parent(Categories.ClientID) .Parent(TxtMealName.ClientID, "mealName"); %><awe:Ocon runat="server" ID="ChildOfManyMealRadioList" />
public class MealBoundToManyController : Controller{ public ActionResult GetItems(int[] parent, string mealName) { mealName = mealName ?? string.Empty; parent = parent ?? new int[] { }; var meals = Db.Meals.Where(o => (parent.Contains(o.Category.Id)) && o.Name.ToLower().Contains(mealName.ToLower())); return Json(meals.Select(o => new KeyContent(o.Id, o.Name))); }}
<% CategorySv.AjaxDropdown() .Url(Page.Url().Action("GetCategories", "Data")); %><awe:Ocon runat="server" ID="CategorySv" /><% MealsSv.AjaxDropdown() .Parent(CategorySv.ClientID, "categories") .Url(Page.Url().Action("GetMealsSetValue2", "Data")); %><awe:Ocon runat="server" ID="MealsSv" />
public ActionResult GetMealsSetValue2(int[] categories){ categories = categories ?? new int[] { }; var items = Db.Meals.Where(o => categories.Contains(o.Category.Id)).ToList(); object value = null; if (items.Any()) { value = items.Skip(1).First().Id; } return Json(new AweItems { Items = items.Select(o => new KeyContent(o.Id, o.Name)), Value = value });}public ActionResult GetOrgSetValue(){ var items = Db.Organisations.ToList(); object value = null; if (items.Any()) { value = items.Skip(2).First().Id; } return Json(new AweItems { Items = items.Select(o => new KeyContent(o.Id, o.Name)), Value = value });}
<% EnumAdd.AjaxDropdown().Url(Page.Url().Action("GetWeatherEnumItems", "Data")); %><awe:Ocon runat="server" ID="EnumAdd" />
public ActionResult GetWeatherEnumItems(){ var type = typeof(WeatherType); var items = Enum.GetValues(type).Cast<int>().Select(o => new KeyContent(o, SplitByCapLetter(Enum.GetName(type, o)))).ToList(); // remove if not needed or if used with odropdown/ajaxradiolist items.Insert(0, new KeyContent(string.Empty, "please select")); return Json(items);}/// <summary>/// from HiThere to Hi There/// </summary>private string SplitByCapLetter(string s){ var r = new Regex(@" (?<=[A-Z])(?=[A-Z][a-z]) | (?<=[^A-Z])(?=[A-Z]) | (?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); return r.Replace(s, " ");}
<% Meal1.AjaxDropdown() .Parameter("categories", cat1.Id) .ParameterFunc("giveParams") .Url(Page.Url().Action("GetMeals", "Data")); %><awe:Ocon runat="server" ID="Meal1" /><script> function giveParams() { return { categories: <%=cat2.Id %> }; }</script>