Hi I'm having problem accessing the text field in a selected value of Html.DropdownList.
My ViewModel is
public class UserViewModel
{
public List<SelectListItem> SupportedCurrency
{
get;
set;
}
public string DefaultCurrency
{
get;
set;
}
}
My controller populates the dropdown list as bellow.
public List<SelectListItem> GetSupportedCurrencies(string setupValue)
{
List<SelectListItem> items = new List<SelectListItem>();
try
{
IList<Currency> currencyList = Helper.GetFormattedCurrenciesList(CurrenciesService.GetSupportedCurrencies());
foreach (Currency c in currencyList)
{
if (!string.IsNullOrEmpty(setupValue) && c.CurrencyCode.Equals(setupValue))
{
items.Add(new SelectListItem
{
Text = c.CurrencyDescription,
Value = c.CurrencyCode,
Selected = true
});
}
else
{
items.Add(new SelectListItem
{
Text = c.CurrencyDescription,
Value = c.CurrencyCode
});
}
}
}
catch (Exception ex)
{
throw ex
}
return items;
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index()
{
userViewData.SupportedCurrency = GetSupportedCurrencies(userModelData.DefaultCurrency);
SelectList SupportedCurrencyList = new SelectList(userViewData.SupportedCurrency, "CurrencyCode", "CurrencyDescription");
.........
}
In View Index <%= Html.DropDownList("userViewModel.DefaultCurrency", Model.SupportedCurrency)%>
......................
No when I do post/update I call a different action (say Update) and I want to access the Currencycode as well as CurrencyDescription. I can get Currencycode but I can't access CurrencyDescription.
Any help greatly appreciated.