0
我填充一个小套在我的模型列表,下拉列表中的项目:ASP MVC3 DropDownListFor空白默认选项
SecSellerCodes = (from s in db.DropDownValues
where s.Field.Equals("SecSellerCd") &&
s.DisplayPage.Equals("Agent Create")
select s).Select(x => new SelectListItem
{
Text = x.DisplayValue,
Value = x.AllowedValue
}).Distinct().ToList();
我希望用户能够从项目的列表中选择从上面的查询中拉出来,再加上列表顶部的空白选项,以防他们不希望填充这个特定字段。
使用以下帮助程序,一旦页面加载/用户保存到数据库,此工作正常。但是,如果他们需要重新加载页面并进行调整,则始终选择空白string.Empty
项目(不管表格中的值)。
@Html.DropDownListFor(model => model.SecSellerCd, Model.SecSellerCodes, string.Empty)
任何想法,用什么样的辅助工具/技术来完成这个?
如果属性'SecSellerCd'的值与'SelectList'中的一个值(即'x.AllowedValue')匹配,那么它将被选中。你确定有匹配的值吗? – 2014-09-30 21:51:29
是的。在这种情况下,显示和允许值是相同的。我已验证该字段中存在有效值。 – NealR 2014-09-30 21:57:11
奇怪。尝试创建'SecSellerCodes'作为'SelectList' - 'var values =(从db.dropDownValues中的s where ... select s); SecSellerCodes = new SelectList(values,“AllowedValue”,“DisplayValue”);' – 2014-09-30 22:05:33