如何在C#中从Drodownlist获得价值

时间:2018-07-17 00:08:55

标签: c# asp.net-mvc

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

0 个答案:

没有答案