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)
這是正確的嗎?
在此先感謝您的幫助。
克萊爾