asp.net mvc中的RadioButtonFor只创建一个radiobutton

时间:2011-03-18 01:43:50

标签: asp.net-mvc

我正在尝试为我的问题创建RadioButtonFor或CheckBoxFor。我创建了这个模型:

    public class Question
    {
        public int ID { get; set; }
        public string Question1 { get; set; }
    }
    public class Answer
    {
        public int ID { get; set; }
        public string Answer1 { get; set; }
        public int QId  { get; set; }
    }
    public class AnModelView
    {
        public Answer Answers { get; set; }
        public IQueryable<Question> Questions { get; set; }
    }

在我看来,我正在尝试这个:

<%:Html.RadioButtonFor(model => model.Answers.QId, new SelectList(Model.Questions.Select(qu => new RadioButtonList { DataValueField = qu.ID.ToString(), DataTextField = qu.Question1 }), "Value", "Text"))%>

但输出只有一个radiobutton。如何获得多个单选按钮 - 每个答案一个

1 个答案:

答案 0 :(得分:1)

您需要一个单选按钮列表,而不是单个按钮。看看这个问题re:Html.RadioButtonListFor ... Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?