I was creating Blogs with ASP.NET MVC 3. I have created the View that list blog post while clicking the Blog navigation link. I have also tried to list the Blog category in Layout to appear the blog category list to every link. The problem is that when I click the blog category list link it shows the runtime error like "Object reference not set to an instance of an object". in this code of _Layout page.
@foreach (Tag tag in (IEnumerable<Tag>)ViewBag.tag)
{
<a href="@Href("~/Posts/Tags/" + tag.Name)"> @tag.Name </a>
}
In Controller of Blogs I have passed the data through ViewBag.
IEnumerable<Tag> tags = from tag in model.Tags select tag;
ViewBag.tag = tags;
Here I have also copy this code to every controller of navigation link Controller for passing data to Layout so that blog category list could appear in all link page.As this is againsts 'DRY'. Would you plz help me so that each blog category link reach to its corresponding category blog.