1

I want to iterate two columns in a row ...

@Html.Partial("_MediumProductWrap", product)

is a column

@foreach (var product in Model.Products)
{
    <div class="row">
        @Html.Partial("_MediumProductWrap", product) // Col
    </div>
}
4
  • It should work if you put the "row" div outside the foreach loop. Then make sure that your partial has a class of col-6, which will cause them to appear as two columns (presuming that you're using bootstrap). Commented Jan 8, 2020 at 17:09
  • if i put row outside loop it put 10 col in a row.because loop count is 10 Commented Jan 8, 2020 at 17:10
  • That's why you need to add the col-6 class to the partial. Please see the following to understand how the Bootstrap grid system works: getbootstrap.com/docs/4.1/layout/grid Commented Jan 8, 2020 at 17:15
  • can u write a code below. .what do u want to say Commented Jan 8, 2020 at 17:17

1 Answer 1

2

Please try the following:

<div class="flex">
  <div class="row">
    @foreach (var product in Model.Products)
    {
      <div class="col-6">
        @Html.Partial("_MediumProductWrap", product) // Col
      </div>
    }
  </div>
</div>

The bootstrap grid system uses a 12 column grid, so setting the div around your partial to have col-6 will make the products display as a grid with 2 columns.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I missed the flex wrapper div around the whole thing. Please see my updated answer. Working fiddle: jsfiddle.net/t1ya8nfc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.