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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:53:06+00:00 2026-05-18T11:53:06+00:00

I have a view that contains a list of items. I loop through those

  • 0

I have a view that contains a list of items. I loop through those items and then I need to return another list based on the item.id from MS SQL.

What is the based way to perform this with custom HTML Helper.

<table width="100%">
 <%foreach(var item in Model.BlogList) %> 
        <%{ %>
    <tr>
        <td>
        <%: Html.ActionLink(item.title, "GetBlog", new { id = item.id, name = item.title }, null)%>
        </td>
    </tr>
    <tr>
        <td>
            <hr />
        </td>
    </tr>
    <tr>
        <td>Date: 
        <%= Convert.ToDateTime(item.createdDate).ToShortDateString() %>
        </td>
    </tr>
    <tr>
        <td>Posted By: 
        <%= item.postedBy %>
        </td>
    </tr>
    <tr>
        <td><span class='blog_post'><%= item.body %></span>
        </td>
    </tr>
     <tr>
        <td>Tags: HERE IS WHERE I need to return a new list based on item.id  (I would need a new SQL SELECT)
        </td>
    </tr>
    <%} %>
</table>
  • 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-18T11:53:07+00:00Added an answer on May 18, 2026 at 11:53 am

    I’d refactor your model so that it includes the data needed by the view. Typically, you’d construct a view-specific model containing the data. This model can “roll up” data from various domain models to encapsulate the data needed by the view.

    For example:

    public class BlogViewModel
    {
        public int ID { get; set; }
        public sring Name { get; set; }
        public DateTime CreatedDate { get; set; }
        public string PostedBy { get; set; }
        public string Body { get; set; }
        public IEnumerable<TagViewMOdel> Tags { get; set; }
    }
    
    public class TagViewModel
    {
        public string Tag { get; set; }
        public int ID { get; set; }
    }
    

    Then in your action (assuming you have an entity relationship between blogs and tags).

    var model = this.Context
                    .Blogs
                    .Select( b => new BlogViewModel {
                        b.ID,
                        b.Name,
                        b.CreatedDate,
                        PostedBy = b.Author.Name,
                        b.Body,
                        Tags = b.BlogTags
                                .SelectMany( bt => bt.Tags )
                                .Select( t => new TagViewModel { t.Tag, t.ID } )
                                .ToList()
                     })
                    .ToList();
    

    Then you have all the data you need without having to involve the data context or perform another DB query.

    <tr>           
        <td><% foreach (var tag in item.Tags) { %>
               <%= Html.ActionLink( tag.Tag, "tag", "search", new { id = tag.ID }, null %>
            <% } %>          
        </td>           
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a View that renders a list of items, and each item contains
I have a view that contains a list of items, a TextBox and a
I'm developing an iOS 4 application. I have a main view that contains another
I have a usercontrol that is rendering a list of items. Each row contains
I have a view with a grid that contains items added to a workstation.
I have list view with custom row layout (list_row.xml) that contains CheckBox element: <TableLayout
I have a view that - among other things - contains a list of
I have a view that contains nested views of the same type. Because of
I have a view that contains two NSTextFieldCell s. The size at which these
I have a view model that contains a Product class type and an IEnumerable<

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.