Dynamically Arrange Bootstrap Column Horizontally in Razor

@{
    int columnCount = 1;
    int contactSerialNo = 0;
}

@foreach (var contact in ViewBag.ContactInfo.Rows)
    {
        contactSerialNo++;
        if (columnCount==1)
        {
           @:<div class="row-fluid">
        }

        <div class="span3">
            <div class="block well">
                <div class="body">
                    <h4>@contactSerialNo.ToString(). @contact["ContactName"].ToString()

                        @if (contact["CallStatusId"].Equals(DBNull.Value))
                        {
                             //Something
                        }
                        else
                        {
                            int callStatusId = contact["CallStatusId"];
                            switch (callStatusId)
                            {
                                case 1:
                                    @:<img src="@(ViewBag.Url)Assets/Icon.png" />
                                    break;
                            }
                        }

                        @if (Convert.ToBoolean(contact["PTR"]) == true)
                        {
                            @:<img src="@(ViewBag.Url)Assets/lighter.png" />
                        }

                    </h4> <br />
                    Son of @contact["FatherName"].ToString(). <br />
                </div>
            </div>
        </div>

        if (columnCount == 4)
        {
             @:</div>
             columnCount = 1;
        }
        else
        {
            columnCount++;
        }
    }

Create JavaScript Array in ASP.NET MVC Razor

Let’s you need to populate this variable in javascript-

Divisions= ["Dhaka", "Khulna", "Rajshahi"];

Way 1: Done in javascript tag.

<script>
  //first declare an empty array
  var Divisions = []; 
  
  //Razor Loop
  @foreach (var row in ViewBag.DivisionTable.Rows)
  {
     <text>
       Divisions.push('@row["DisionName"].ToString()');
     </text>
  }
</script>

Way 2: Done in C#

string[] Divisions = new string[qty];
//int[] data = new int[qty];

for (int i = 0; i < DivisionQty; i++)
{
   Divisions[i]= Table.Rows[i]["DivName"].ToString();
}

ViewBag.Divisions=Divisions;

//Now in javascript-
var Divisions = @Html.Raw(Json.Encode(ViewBag.Divisions));

Nesting foreach within If statement in ASP.NET Razor

 @foreach (var row in ViewBag.Contents.Rows)
 {
    <text> //wrap all code inside this tag
       <div class="row">
       <div class="col-lg-12"> 
       @if (row["ContentType"].ToString()=="Pdf")
       {
         <p style="margin-top:10px;"> @Html.Raw(row["Caption"].ToString()) <a href="~/LessonDetails/ViewFullPagePdf?contentid=@row["ContentId"]">View in full screen</a></p>
       }
       else
       {
         <p style="margin-top:10px;"> @Html.Raw(row["Caption"].ToString())</p>
       }
       <p style="margin-top:10px;">@Html.Raw(row["ContentDetails"].ToString())  </p>
       </div>
       </div>
       

       

    </text>
   counter = counter + 1;
}