我有这个控制器:
public class NewPostController : Controller
{
List<SelectListItem> languages= new List<SelectListItem>();
public ActionResult Index()
{
ViewData["languages"] = new SelectList(languages, "Text", "Value", 1);
return View();
}
private void GetCountryList()
{
CultureInfo[] cultureList = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultureList)
{
languages.Add(new SelectListItem
{
Text = culture.DisplayName,
Value = culture.DisplayName,
});
}
}
}
项目清单应按其语言建立并传递给视图。
@Html.DropDownList("languages",null,
"** Please Select **",
new { @class = "my-select-css-class" })
什么都没有填充..为什么?
答案 0 :(得分:1)
GetCountryList()
你永远不会打电话。