开发者

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 t开发者_高级运维he Model passed.......

Displaying List elements in Razor view

.

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>
}


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 */
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜