2011-03-18 62 views
2

我正在尝试为我的问题创建RadioButtonFor或CheckBoxFor。我创造了这个模式:RadioButtonFor在asp.net mvc只创建一个单选按钮

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"))%>

但产量只有一个单选按钮。我如何获得多个单选按钮 - 每个答案都有一个

+0

你可以使用radioibuttonlist助手从这里:http://awesome.codeplex.com – Omu 2011-05-20 17:21:48

回答

1

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

+0

我很惊讶为什么所有这一切,有没有另一种解决方案我的问题 – Abdalmohaymen 2011-03-18 09:34:04

+0

你可以在一个循环内创建你的按钮... – 2011-03-18 12:16:59

+0

征收确定我需要这个,但如何绑定模型=> model.Answers.QId与选择值 – Abdalmohaymen 2011-03-18 18:39:43

相关问题