我有2个模型。在mvc中合并2个相关模型
public partial class Question
{
public int QuestionId { get; set; }
public string QuestionText { get; set; }
public string Ans1 { get; set; }
public string Ans2 { get; set; }
public string Ans3 { get; set; }
public string Ans4 { get; set; }
}
public partial class UserAnswer
{
public int UserAnsId { get; set; }
public Nullable<int> QuestionId { get; set; }
public Nullable<int> UserId { get; set; }
public Nullable<int> AnsVal { get; set; }
}
正如你可以看到QuestionId在两个模型中。我如何在视图中渲染它。有很多问题。问题Moldel在初始运行时有数据,但UserAnswer没有。
如何组合这两个模型,以便我可以将它用作IEnumerable中的视图。 Ans1,Ans2,Ans3,Ans4在UserAnswer中有文本和AnsVal将从Raiobutton得到它的值。
你想要在视图中使用组合模型? –
是的,以便我可以在视图中重新指定它。 – user952072
您可以使用Neel Bhatt的建议。 –