0

My ViewBag line is throwing a 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 method is:

   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;
    }

Im not sure what the NullReference is reffering too or why it would be a NullReference in the first place?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
ASPCoder1450
  • 1,651
  • 4
  • 23
  • 47
  • You forgot to include KnowledgebaseSuggestions.cshtml file? That's where the exception might be occuring.. – Ostati Mar 21 '14 at 23:17
  • That file is a part of my solution and is in the correct place. – ASPCoder1450 Mar 21 '14 at 23:22
  • And `ViewBag`, `KS`, and `IncidentTags` are definitely not null? – jdphenix Mar 21 '14 at 23:30
  • 1
    Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Mar 21 '14 at 23:31

1 Answers1

0

Forgot to rename my route attributes

ASPCoder1450
  • 1,651
  • 4
  • 23
  • 47
  • It's better for self-answers to place it as an answer, even if it's not a full answer, so that they can accept it. Comments are only meant to be temporary. Better yet, the OP could delete the question. If this answer is deleted, we have no way of knowing that the OP actually solved the issue, even if it's not a "proper" answer by Stack Overflow standards. – Qantas 94 Heavy Mar 22 '14 at 00:33