Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6905057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:08:14+00:00 2026-05-27T08:08:14+00:00

I was creating Blogs with ASP.NET MVC 3. I have created the View that

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:08:15+00:00Added an answer on May 27, 2026 at 8:08 am

    I implemented tag categories a little differently on my blog.

    I created a folder which I called HtmlHelpers inside of my project. Inside of this I have a class called DisplayHelpers.cs which contains code like this.

    namespace ProjectName.HtmlHelpers
    {
        public static class DisplayHelpers
        {
            public static MvcHtmlString GetTags()
            {
                var tags = from tag in model.Tags select tag;
    
                StringBuilder sb = new StringBuilder();
    
                foreach (Tag tag in tags)
                {
                    sb.AppendFormat("<a href="{0}"> {1} </a>",
                         // link,
                         tag.Name);
                }
    
                return new MvcHtmlString(sb.ToString());
            }
        }
    }
    

    Now from within your _Layout.cshtml page, call this function like this:

    @DisplayHelpers.GetTags()
    

    Now your tags should appear wherever you call this function!

    On a side note, could I convince you to embed the anchor tags in an unordered list? Since it acts as a “Collection” of tag links, putting them in a list helps to organize them into single “entity”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any experience creating a skin engine for asp.net MVC? I know
Followed http://damieng.com/blog/2010/04/26/creating-rss-feeds-in-asp-net-mvc to create RSS for my blog. Everything fine except html tags in
I am reading a post about mobile web development and ASP.NET MVC here: http://www.hanselman.com/blog/ABetterASPNETMVCMobileDeviceCapabilitiesViewEngine.aspx
I am creating list of checkboxes in partial view by follwoing http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ code and
I have started to learn ASP.NET MVC, and at this time of studying I
I was checking out this link: http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx which describes creating a jquery datepicker for
I am a bit confused with this paticular blog post here... http://bartdesmet.net/blogs/bart/archive/2006/09/13/4417.aspx What is
Hey all, brand new to asp.net mvc and I am creating a fake social
I'm planning to write an MVC blog engine, supporting multiple blogs. When creating a
I’m in the process of creating a new C# asp.net mvc 3.0 project. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.