Setup:
I installed the controller using MvcScaffolding.
For the Model.IdCurrencyFrom property, the scaffolding created the Html.DropDownListFor:
@Html.DropDownListFor(model => model.IdCurrencyFrom, ((IEnumerable<FlatAdmin.Domain.Entities.Currency>)ViewBag.AllCurrencies).Select(option => new SelectListItem { Text = (option == null ? "None" : option.CurrencyName), Value = option.CurrencyId.ToString(), Selected = (Model != null) && (option.CurrencyId == Model.IdCurrencyFrom) }), "Choose...")
This works great with both new recordings and editing existing ones.
Problem:
There are only 3 currencies: AR $, US $ and GB Β£. So, instead of a drop down list, I need a ListBox.
So, I changed the above:
@Html.ListBoxFor(model => model.IdCurrencyFrom, ((IEnumerable<FlatAdmin.Domain.Entities.Currency>)ViewBag.AllCurrencies).Select(option => new SelectListItem { Text = (option == null ? "None" : option.CurrencyName), Value = option.CurrencyId.ToString(), Selected = (Model != null) && (option.CurrencyId == Model.IdCurrencyFrom) }))
Now I get an ArgumentNullException, Parameter name: source, but only when editing an existing record. Creating new records, this works great.
Questions:
What's happening?!
Nothing changed. Return to DropDownListFor and everything works fine. Switching to ListBox (unlike ListBoxFor), and I get an error.
The model is not null (as I said, it works great with DropDownListFor) ... and I ran out of ideas.
awrigley
source share