dropdown box query

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

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

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

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.



Roland
Aug 1, 2013 at 8:31 AM

Thanks for your reply Roland,

I will have a go at doing this.

Kirsty