【发布时间】:2011-01-12 00:19:02
【问题描述】:
我在访问 Html.DropdownList 的选定值中的文本字段时遇到问题。
我的 ViewModel 是
public class UserViewModel
{
public List<SelectListItem> SupportedCurrency
{
get;
set;
}
public string DefaultCurrency
{
get;
set;
}
}
我的控制器填充下拉列表如下。
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");
.........
}
查看索引
......................
不,当我发布/更新时,我会调用不同的操作(比如更新),并且我想访问 Currencycode 以及 CurrencyDescription。我可以获取 Currencycode,但无法访问 CurrencyDescription。
非常感谢任何帮助。
【问题讨论】:
标签: asp.net-mvc drop-down-menu