2014-09-11 131 views
1

我有大约35个单选按钮列表值将显示在我的视图中使用@ html.RadioButtonFor在.cshtml页面中的html助手。如何在mvc4中水平和垂直对齐单选按钮列表值?

我想显示在9列和4行。

在使用类似“RepeatLayout”,“RepeatDirection”,“RepeatColumns”的控件属性的Asp.net中,我们可以实现这一点。

我想将它应用于mvc4.Is是否有任何方法来实现相同的东西?

请帮忙!

控制器代码:

ViewBag.Ratio = query.Select(m => new SelectListItem { Value = m.RatioID, Text = m.Ratio_Description }); 

.cshtml代码

<td colspan="3" > 

      @foreach (var item in (IEnumerable<SelectListItem>)ViewBag.Ratio) 
        { 
         @Html.RadioButtonFor(m => m.RatioType, new { @item.Value, @item.Text }) 
         <label for = "@item.Value">@item.Text</label> 

        } 


      </td> 
+0

您可以通过使用[第n个孩子()](http://www.w3schools.com/cssref/sel_nth-child.asp) – glautrou 2014-09-11 13:32:31

+0

请粘贴代码 – Jay 2014-09-11 13:35:46

+0

周杰伦嗨,这是适应你的CSS我的代码 – Himani 2014-09-12 08:54:01

回答

0

最好的办法是用表是这样的:http://jsfiddle.net/z2L3qbh9/1/ 或尝试用这样的CSS来管理它:

.eachRadioBtn{ 
    width:11%; 
    float:left; 
} 

用div标记包裹每个radioBottuon:

<div class=".eachRadioBtn"> 
    @HTML.RadioButtonFor(...) 
</div> 
+0

嗨马苏德,我不能使用像jsfiddle演示,因为我正在使用foreach循环获取值 – Himani 2014-09-12 10:11:57

+0

@ user3406037你可以从浏览器中复制粘贴代码并将其粘贴到css应用! – 2014-09-12 10:12:44

+0

@ user3406037,嗨。尝试替代方式(.eachRadio)。也可以为每个你可以定义一个变种:int i = 0;当我%9 == 0;关闭预览tr并添加新的tr – Masoud 2014-09-12 13:12:13