This project is read-only.

dropdown box query

Topics: Customizing Orchard, General
Jul 30, 2013 at 1:40 PM

can someone tell me how to populate a dropdown box with the results from a query please?

Thanks, Kirsty
Jul 30, 2013 at 9:42 PM
Edited Jul 30, 2013 at 9:43 PM

The way I do it is create a ViewModel, I populate this with the results from my query.
Then in my view I use the following
        @Html.DropDownListFor(m => m.DefaultCurrency,
                      Model.Currencies.Select(s => new SelectListItem
                          Selected = (currencyCurrency == s.Id),
                          Text = string.Format("{0} ({1})", s.Description, s.Symbol),
                          Value = s.Id.ToString()
                      "Choose a currency...")
So in this case my viewmodel has an IEnumerable<MyPart> called Currencies, which I set from my query.

Aug 1, 2013 at 9:31 AM

Thanks for your reply Roland,

I will have a go at doing this.