2014-09-11 43 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