我在访问Html.DropdownList的选定值中的文本字段时遇到问题。
我的ViewModel是
public class UserViewModel
{
public List SupportedCurrency
{
get;
set;
}
public string DefaultCurrency
{
get;
set;
}
}
我的控制器将下拉列表填充为下方。
public List GetSupportedCurrencies(string setupValue)
{
List items = new List();
try
{
IList 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");
.........
}
在视图索引中
<%= Html.DropDownList(“userViewModel.DefaultCurrency”,Model.SupportedCurrency)%>
......................
不,当我发布/更新时,我调用不同的操作(比如更新),我想访问Currencycode以及CurrencyDescription。我可以获得Currencycode但我无法访问CurrencyDescription。
任何帮助非常感谢。