c# - 如何从 C# 中的 Drodownlist 中获取值
问题描述
GetCurrency(countrydetials.Country)
给了我currency
那个特定的国家。但在我的情况下,我的 Currency
下拉列表中只有两种货币。如果country
匹配项currency
在下拉列表中不可用,currency
则默认情况下应选择Indian Rupee
。
控制器代码
CountryDetials countrydetials = new CountryDetials();
var model = GetCurrency(countrydetials.Country);
countrydetials.Currency = model.FirstOrDefault().Currency;
看法
@Html.DropDownListFor(m => m.Currency, new List<SelectListItem>
{
new SelectListItem {Value = "INR", Text="Indian Rupee" },
new SelectListItem {Value = "NPR", Text = "Nepalese Rupee" },
},
new { @class = "form-control" })
@Html.DropDownListFor(m => m.Country, new List<SelectListItem>
{
new SelectListItem {Value = "IND", Text = "India" },
new SelectListItem {Value = "NEP", Text = "Nepal" },
new SelectListItem {Value = "SIN", Text = "Singapore" },
new SelectListItem {Value = "USA", Text = "USA" },
},
new { @class = "form-control"})
解决方案
推荐阅读
- javascript - React.js- 具有行跨度的动态表
- mongodb - 在 mongo 中批量插入文档并进行重复处理
- c# - 在所有测试用例中都需要 chrome 驱动器实例 selenium c#
- bash - 如何使用 Ammonite Script 运行“set”或“source”
- javascript - 是否可以在 solr 集合 url 中传递用户/传递
- angular - 为什么 FormControlName 如果在 FormArray 中的不同 FormGroup 下复制值
- python - 我们可以为 pandas 进行数据帧级别的异常处理吗?
- android - Android中的DownloadManager没有显示进度条?
- sql-server - 中间有标量变量的 SELECT 语句
- python - 有没有办法使用 Python Win32com 模块读取任何本地 PST 文件并将消息导出为 MSG 文件?