2
我有一个yes/no单选按钮,需要访问另一个aspx表单上的值。我不知道我是否做对了?访问IEnumerable mvc2单选按钮的值
主视图模型
[UIHint("YesNoEditorTemplate")]
[DisplayName("Are you registered as blind (severely sight impaired)?")]
public IEnumerable<RadioButtonViewModel> RegBlind { get; set; }
单选按钮视图模型
public class RadioButtonViewModel
{
public string ID { get; set; }
public string Name { get; set; }
public int Value { get; set; }
public string Text { get; set; }
}
控制器
List<RadioButtonViewModel> regBlindList = new List<RadioButtonViewModel>();
regBlindList.Add(CreateRadioButton("RegBlind", 1, "Yes"));
regBlindList.Add(CreateRadioButton("RegBlind", 0, "No"));
badgeViewModel.RegBlind = regBlindList;
编辑模板
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Tameside.Internal.ViewModels.BlueBadge.RadioButtonViewModel>>"%><%
foreach (var model in Model)
{%>
<tr>
<td><%=String.Format("<input type=\"radio\" id=\"{0}\" name=\"{1}\" value=\"{2}\" />", model.ID, model.Name,model.Value)%></td>
<td><%=String.Format("<label for=\"{0}\">{1}</label>", model.ID, model.Text)%></td>
</tr><%
}%>
ASPX页面
<%=Html.EditorFor(x => x.RegBlind)%>
这里是我正在访问信息
if (Model.RegBlind.First().Value == 0)
这是正确的吗?
在此先感谢您的帮助。
克莱尔