在 .cshtml 页面中使用 @html.RadioButtonFor html 帮助器,我有大约 35 个单选按钮列表值要显示在我的 View 中。
我想显示成9列4行。
在 Asp.net 中,使用“RepeatLayout”、“RepeatDirection”、“RepeatColumns”等控件属性,我们可以实现这一点。
我想将它应用于 mvc4。有什么方法可以实现吗?
请帮忙!
Controller 代码:
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>
最佳答案
最好的方法是使用这样的表:http://jsfiddle.net/z2L3qbh9/1/ 或者尝试用这样的 css 来管理它:
.eachRadioBtn{
width:11%;
float:left;
}
用 div 标签包裹每个 radioBottuon:
<div class=".eachRadioBtn">
@HTML.RadioButtonFor( ... )
</div>
关于c# - 如何在 mvc4 中水平和垂直对齐单选按钮列表值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25788701/