【发布时间】:2015-10-22 07:53:13
【问题描述】:
您好,我在 mvc5 中创建下拉列表时遇到问题, 这就是我的模型中的内容:
public string CountryCode { get; set; }
public LocationChecker()
{
PopulateCountryCodes();
}
public IEnumerable<SelectListItem> CountryCodes { get; set; }
private void PopulateCountryCodes()
{
CountryCodes = new List<SelectListItem>();
CountryCodes.Add (new SelectListItem {Value = "1", Text =“UK”});
CountryCodes.Add (new SelectListItem {Value = "2", Text =“GB”});
CountryCodes.Add (new SelectListItem {Value = "3", Text =“IRL”});
}
这是我的观点:
<h4>Countries</h4>
add a drop down list
@Html.DropDownListFor(m => m.CountryCode, Model.CountryCodes)
</div>
CountryCodes.Add 中的 ADD 是红色的,无法解决,而且我在 UK、GB 和 IRL 之前还有“预期表达式”错误。
任何帮助将不胜感激。这是我第一次使用 mvc5 顺便说一句。
谢谢
导航
【问题讨论】:
标签: c# asp.net-mvc drop-down-menu asp.net-mvc-5 selectlistitem