Created
April 23, 2012 21:28
-
-
Save nootn/2473983 to your computer and use it in GitHub Desktop.
MVC Mega Forms quick start guide - CascadingSelectList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MegaFormsCascadeJQueryHideEffect = 'fast'; //sets the jQuery effect to use when hiding a child cascaded list just before refreshing its items | |
var MegaFormsCascadeJQueryShowEffect = 'fast'; //set the jQuery effect to use when showing a child cascaded list just after refreshing its items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<SelectListItem> AllParentItems { get; set; } | |
public int ParentItemId { get; set; } | |
public CascadingSelectList AllChildItems { get; set; } | |
public int ChildItemId { get; set; } | |
public void PopulateAllTestDropDownItems() | |
{ | |
AllParentItems = new List<SelectListItem>(); | |
AllParentItems.Add(new SelectListItem {Text = "[Please Select]", Value = "0"}); | |
AllParentItems.Add(new SelectListItem {Text = "Parent 1", Value = "1"}); | |
AllParentItems.Add(new SelectListItem {Text = "Parent 2", Value = "2"}); | |
AllParentItems.Add(new SelectListItem {Text = "Parent 3", Value = "3"}); | |
AllChildItems = new CascadingSelectList(); | |
AllChildItems.ParentSelectListPropertyName = "ParentItemId"; //This is the key to how it works, this links the parent list | |
AllChildItems.Add(new ChildSelectListItem {Text = "[Please Select]", ParentValue = "1", Value = "0"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "Child 1 of Parent 1", ParentValue = "1", Value = "1"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "[Please Select]", ParentValue = "2", Value = "0"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "Child 1 of Parent 2", ParentValue = "2", Value = "2"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "Child 2 of Parent 2", ParentValue = "2", Value = "3"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "[Please Select]", ParentValue = "3", Value = "0"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "Child 1 of Parent 3", ParentValue = "3", Value = "4"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "Child 2 of Parent 3", ParentValue = "3", Value = "5"}); | |
AllChildItems.Add(new ChildSelectListItem {Text = "Child 3 of Parent 3", ParentValue = "3", Value = "6"}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldset> | |
<legend>Please fill in the form</legend> | |
<ol> | |
<li class="container"> | |
@Html.LabelFor(m => m.ParentItemId) | |
@Html.DropDownListFor(m => m.ParentItemId, Model.AllParentItems) | |
@Html.ValidationMessageFor(m => m.ParentItemId) | |
</li> | |
<li class="container"> | |
@Html.LabelFor(m => m.ChildItemId) | |
@Html.DropDownChildListFor(m => m.ChildItemId, Model.AllChildItems) | |
@Html.ValidationMessageFor(m => m.ChildItemId) | |
</li> | |
</ol> | |
<input type="submit" value="submit" /> | |
</fieldset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment