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"})