lettucebo / MvcDynamicForms

Create dynamic forms in ASP.NET MVC.
52 stars 28 forks source link

Select functionality #16

Closed suhbcc closed 3 years ago

suhbcc commented 3 years ago

Hello, How would you pre-select an option in a Select when you are generating the form? Instead of a list of strings, would it be possible to set a select to a list of ids/values? Thank you very much!

suhbcc commented 3 years ago

Sorry, found it!

                    ListItem l1 = new ListItem() { Selected = false, Text = "A", Value = "1" };
                    list.Choices.Add(l1);
                    ListItem l2 = new ListItem() { Selected = true, Text = "B", Value = "2" };
                    list.Choices.Add(l2);
                    ListItem l3 = new ListItem() { Selected = false, Text = "C", Value = "3" };
                    list.Choices.Add(l3);