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 t开发者_运维技巧his:
<%: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
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?
精彩评论