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

  • Home
  • SEARCH
  • 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 6252601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:50:04+00:00 2026-05-24T13:50:04+00:00

I have an ASP.NET MVC3 project. I want to insert some <td> ‘s in

  • 0

I have an ASP.NET MVC3 project.

I want to insert some <td>‘s in one table <tr>. These <td>‘s contain one <div> each. These comes from a switch() which is in a partialView and renders into another View (where is the <tr> which could contain multiple <td>‘s).

This is the partialView:

@foreach (var item in Model)
{
   switch (item.PitlaneId)
       {
           case 1:
                   <td id=a>
                       <div class="drag">
                           Name: @Html.DisplayFor(modelItem => item.Name) <br />
                           Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
                       </div>
                   </td>
           break;

           case 2:
                   <td id=b>
                       <div class="drag">
                           Name: @Html.DisplayFor(modelItem => item.Name) <br />
                           Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
                       </div>
                   </td>
           break;

           case 3:
                   <td id=c>
                       <div class="drag">
                              Name: @Html.DisplayFor(modelItem => item.Name) <br />
                              Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
                          </div>
                   </td>
           break;

           default: break;
       }
}

And this partialView renders here:

<table title="test" id="testTableID">
   <colgroup> @foreach (var item in Model){<col width="300" />} </colgroup>
   <tbody>
      <tr>
         @{Html.RenderAction("Tasks"); }  @* <--- Here it renders*@
      </tr>
   </tbody>
</table>

The PROBLEM appears when switch() goes to the same case multiple times. If I have PitlaneId in this order: 1,2,2,3; It will create 4 <td>‘s in my table. In this case I should have only 3 <td>‘s and the two <div>‘s with the same PitlaneId=2 should be inside the same <td>. I mean <td>‘s with the same id should merge together. Same situation when PitlaneId comes in this order: 1,2,3,2.

  • 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-24T13:50:05+00:00Added an answer on May 24, 2026 at 1:50 pm

    This is the only way I could make it work. It seems smelly, but it provides the order of elements you specified.

    @Html.Raw("<table><tr><th>ID 1</th><th>ID 2</th><th>ID 3</th></tr><tr>")
    
    @foreach (int id in Model.OrderBy(p => p.PitlaneID)
        .Select(p => p.PitlaneID).Distinct())
    { 
        switch(id)
        {
            case 1:  
                @:<td id="a">
                break;
            case 2:  
                @:<td id="b">
                break;
            case 3:  
                @:<td id="c">
                break;
            default: break;
        }
    
        foreach (var item in Model.Where(p => p.ID == id))
        { 
            <div class="drag">
                Name: @Html.DisplayFor(modelItem => item.Name) <br />
                Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
            </div>
        }
    
        Html.Raw("</td>");
    }
    
    @Html.Raw("</tr></table>")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net mvc3 project where I do a bulk edit on a table
I have MVC3 asp.net project. I create controller function with some parameters, the question
I have an ASP.NET MVC3 project that has a database. I want to attach
I have an ASP.NET MVC1 project and want to upgrade it directly to MVC3.
I have an asp.net mvc3 project, it has some reports in aspx web pages.
I have some C# code in my ASP.NET MVC3 project that's throwing an exception
In an ASP.NET MVC3 project I have a structure like this: Core.csproj -> 3rdparty1.dll
In a ASP.NET MVC3 Razor project I have 2 Models public class Post {
I have a MVC3 ASP.NET Project in which I am using jQuery and KendoUI
i have a problem with the asp.net MVC3. when i create a new project

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.