是否可以在视图中向列表中添加多个项目?假设我在下面有以下数据合同:
public class Question
{
public int QuestionID { get; set; }
public string Name { get; set; }
public virtual List<AdditionalAnswer> AdditionalAnswers { get; set; }
}
public class AdditionalAnswer
{
public int AdditionalAnswerID { get; set; }
public AnswerTypeAnswerTypeEnum AnswerType { get; set; }
}
如果我要创建新的Question
,如何在AdditionalAnswers
视图中添加多个Edit
而不进行任何回复?
答案 0 :(得分:1)
默认的模型绑定应该能够做到。诀窍是动态添加类似于:
的输入标签<input name="AdditionalAnswer[0].AdditionalAnswerID"/>
<input name="AdditionalAnswer[0].AnswerType"/>
<input name="AdditionalAnswer[1].AdditionalAnswerID"/>
<input name="AdditionalAnswer[1].AnswerType"/>