我的视图中有以下内容:
@Html.DropDownListFor(model => model.Search, new SelectList(Model.SearchOptions))
在我的搜索对象中,我有:
public List<string> Search { get; set; }
public Dictionary<string, string> SearchOptions { get; set; }
public SearchModel GetDropDownOptions(SearchModel model)
{
model.SearchOptions = HelperModel.GetRefValues(db, Constants.SEARCH, false);
return model;
}
随着它的调用:
public static Dictionary<String, String> GetRefValues(DBEntities db, string refType, bool addEmpty)
{
Dictionary<String, String> res = (from c in db.References
where c.Type == refType
select c).ToDictionary(c => c.Key.ToString(),
c => c.Value.ToString());
if (addEmpty)
res.Add("", "");
return res;
}
但是,我收到一条错误消息:“对象引用未设置为对象的实例。”
建议表示赞赏。
谢谢。