开发者

RadioButtonFor in asp.net mvc only creates one radiobutton

开发者 https://www.devze.com 2023-02-18 01:47 出处:网络
I \'m trying to create RadioButtonFor or CheckBoxFor for my Question.I created this model: public class Question

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号