我的ViewBag行抛出NullReferenceException:
public ActionResult KnowledgebaseSuggestions(String IncidentTags)
{
KnowledgeService KS = new KnowledgeService(db);
ViewBag.KSResults = KS.GetSuggestionsByTags(IncidentTags.Split(',').Select(t => t.Trim()).ToList());
return View();
}
GetSuggestionsByTags方法是:
private readonly db_SLee_FYPContext db;
public KnowledgeService(db_SLee_FYPContext db)
{
this.db = db;
}
public IEnumerable<KnowledgebaseViewModel> GetSuggestionsByTags(IEnumerable<string> tags)
{
var validSuggestions = db.Knowledgebases.Where(k => tags.Any(t => k.KnowledgebaseTitle.Contains(t)))
.Select(k => new KnowledgebaseViewModel()
{
ID = k.KnowledgebaseID,
Title = k.KnowledgebaseTitle,
Link = k.KnowledgebaseLink
})
.ToList();
return validSuggestions;
}
我不确定NullReference正在提供什么,或者为什么它首先是NullReference?
答案 0 :(得分:0)
忘记重命名我的路线属性