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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:23:12+00:00 2026-06-06T18:23:12+00:00

In my view, I use a partial view with a list of objects from

  • 0

In my view, I use a partial view with a list of objects from my model as follows:

@foreach (var item in Model.MyObjectList)
{
    @Html.Partial("DisplayObject", item)   
}

This forms a grid pattern down my main view, 1 row for each object.

I’d like to stripe them using normal method of odd rows one colour, even rows another. (like this for example.

Usually you’d do this by doing some kind of mod calculation.

The question is I can’t figure out how to do this without passing in a row number in the item into the partial view.

Is there an easier way? Html.Partial does not have any html attributes I can hook into.

I could of course put a table around the partial and stripe it that way, but would prefer not to.

  • 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-06T18:23:13+00:00Added an answer on June 6, 2026 at 6:23 pm

    If you can limit support to CSS3 you can use the :nth-child(odd) and :nth-child(even) rules – as shown on this page from W3C – http://www.w3.org/Style/Examples/007/evenodd.en.html

    Those examples show how to use it on tr tags – but it applies to anything that you can apply a selector to:

    <style type="text/css">
      div p:nth-child(odd) { color:red; }
      div p:nth-child(even) { color:green; }
    </style>
    <div>
      <p>first</p>
      <p>second</p>
      <p>third</p>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view for displaying a list of items, I use this
I have a partial view that loops through its Model (a list of things)
The client will choose an item from a dropDown list, this newly selected value
When i load a partial view with this jquery : $.get('@Url.Action( List , Menu
I have this partial view rendered multiple times on a page: @model POS.Domain.Entities.Category <div
I have a view where I use a dropdown list with enum: public enum
I have a view model with a collection of other objects in it. public
In a .NET MVC partial view, I'd like to do something like this: <%
I have a strongly typed partial view CheckBox.ascx that renders a checkbox. This is
I have a scenario I want to use a partial view but I'm having

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.