开发者

How to format view results in mvc3?

开发者 https://www.devze.com 2023-04-12 16:47 出处:网络
I have List of checkbox in my view. it shows me in vertical format. Like a b c d ... But i want to format that in such a way that will look like.

I have List of checkbox in my view. it shows me in vertical format. Like

a

b

c

d

...

But i want to format that in such a way that will look like.

a b c d

e f g h

i j k l

My code looks like this

 @foreach (var item in Model)
 开发者_Python百科 {
  <table>
      <tr>
         <td><input type="checkbox" id="@item.DataId" name="Data"/>@item.DataName</td>
      </tr>
  </table>

How can i format this?


Hoping you're not using the table for layout purposes ;)

Anyway this should do the trick, it's rough code, and could be polished but hopefully this will give you a good start

<table>
    <tr>
@{var rower = 0;}
    @foreach (var item in Model)
    {
        if (rower % 4 == 0 && rower != 0)
        {
            @:</tr>
            @:<tr>
        }
         <td><input type="checkbox" id="@item.DataId" name="Data"/>@item.DataName</td>
        rower++;
    }
    </tr>
</table>


Assuming you need a list, not a table:

// You may to check here whether model contains any items

<ul>
@foreach (var item in Model)
{
   <li><input type="checkbox" id="@item.DataId" name="Data"/>@item.DataName</li>
}
</ul>

In your CSS you need to set display property of the list to inline

0

精彩评论

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