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 8040275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:50:39+00:00 2026-06-05T03:50:39+00:00

I have a problem displaying most popular tags from database in view. I’m not

  • 0

I have a problem displaying most popular tags from database in view. I’m not sure about this question title so if someone has a better one please do rename it.

Scenario

I need to show recent posts, recent galleries and most popular tags on my index page. I decided to use tuples for this and it worked fine until I tried to show most popular tags.

Error

The model item passed into the dictionary is of type
‘System.Tuple3[photoBlog.Models.Gallery[],photoBlog.Models.Post[],System.Linq.IGrouping2[System.Int32,photoBlog.Models.PostTag][]]’,
but this dictionary requires a model item of type
‘System.Tuple`3[photoBlog.Models.Gallery[],photoBlog.Models.Post[],photoBlog.Models.PostTag[]]’.

As you can see it gives my view wrong object type. I want expect it to be an array, but it gives me some kind of System.Linq.Grouping item.

Code

As you can see I convert it into array in my controller.

public ActionResult Index()
{
    photoBlogModelDataContext _db = new photoBlogModelDataContext();
    var posts = _db.Posts.OrderByDescending(x => x.DateTime).Take(4).ToArray();
    var galleries = _db.Galleries.OrderByDescending(x => x.ID).Take(4).ToArray();
    var posttags = _db.PostTags.GroupBy(x => x.TagID).OrderBy(x => x.Count()).Take(4).ToArray();
    return View(Tuple.Create(galleries, posts, posttags));
}

My view is straight forward, note that this did work until I tried to add most popular tags.

@model Tuple<photoBlog.Models.Gallery[], photoBlog.Models.Post[], photoBlog.Models.PostTag[]>
@foreach (var tag in Model.Item3)
{ 
    @tag.Tag.Name
}
  • 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-06-05T03:50:41+00:00Added an answer on June 5, 2026 at 3:50 am

    You probably want

    var posttags = _db.PostTags
        .GroupBy(x => x.TagID)
        .OrderBy(x => x.Count())
        // Take each group and pass the first tag of the group
        .Select(g => g.First())
        .Take(4)
        .ToArray();
    

    At the moment you’re passing e.g. all 8 instances of the most popular tag, all 5 instances of the second most popular, etc., each in their own group. I imagine you just want to pass an “example” of each tag.

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

Sidebar

Related Questions

I am not sure why this issue has risen up, never had this problem
I have problem with displaying adsense ads in ie7 google adsense adds an iframe
I have a problem consistently displaying Facebook Comments on my AJAX driven website. Each
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have two of the most popular plugins installed - minibufexpl.vim and taglist.vim .
I have a problem getting this JPA query to work on MS SQL Server
I'm attempting to implement this paper . I've have most of it down, but
I`m building simple app which shows information about most car brands. I have rootViewController
I researched this problem already, heres what I know: It's most likely a CSS
I have problem with fancybox. I want to write a function that will run

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.