Abdalmohaymen
Abdalmohaymen

Reputation: 89

RadioButtonFor in asp.net mvc only creates one radiobutton

I 'm trying to create RadioButtonFor or CheckBoxFor for my Question. I created this model:

    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; }
    }

In my view I am trying this:

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

but the output is only one radiobutton. How can I get multiple radiobuttons - one for each answer

Upvotes: 2

Views: 1642

Answers (1)

Robert Levy
Robert Levy

Reputation: 29073

You want a list of radiobuttons, not a single one. Check out this question re: Html.RadioButtonListFor... Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?

Upvotes: 1

Related Questions