Pankaj Upadhyay
Pankaj Upadhyay

Reputation: 13574

Displaying List elements in Razor view

I am passing a list to the view from Controller. How can i generate the following type of HTML by using the Model passed....... enter image description here.

I tried using the following code, but it generates a vertical list whereas i want it to be horizontal as well as vertical. Here's my code. How will you write your's to achieve an output like above

@foreach (var cats in Model)
{
    <li>@cats.CategoryName</li>
}

Upvotes: 4

Views: 12973

Answers (1)

Dan Turner
Dan Turner

Reputation: 2243

You need to combine this mark-up with some css:

<ul class="two-columns clearfix">
@foreach (var cats in Model)
{
    <li>@subcats.CategoryName</li>
}
</ul>

Then the CSS:

ul.two-columns li
{
    width: 50%;
    float: left;
    margin: 0;
    padding: 0;
    list-style-type: none;
}

/* Clear Fix */
.clearfix:after
{
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
}


* html .clearfix             { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */

Upvotes: 8

Related Questions