【发布时间】:2013-06-26 16:36:32
【问题描述】:
我有这张桌子
[Table("Quiz")]
public class Quiz
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int QuizId { get; set; }
public string Content { get; set; }
public string Submitby { get; set; }
public virtual ICollection<Score> Scores { get; set; }
}
还有这个
[Table("Score")]
public class Score
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ScoreId { get; set; }
public int QuizId { get; set; }
public string Answer { get; set; }
public virtual Quiz Quiz { get; set; }
}
所以我有这个视图模型
public class ScoreQuizViewModel
{
public Score Score { get; set; }
public Quiz Quiz { get; set; }
}
制作这个控制器
public ActionResult Details(int id = 0)
{
Quiz quiz = db.Quizs.Find(id);
if (quiz == null)
{
return HttpNotFound();
}
return View(new ScoreQuizViewModel());
}
问题是,我的视图中没有显示任何内容 我正在使用
@model SeedSimple.Models.ScoreQuizViewModel
并使用
访问@Html.DisplayFor(model => model.Quiz.Content)
如果我不使用视图模型,我可以看到结果。 我该如何解决这个问题?
【问题讨论】:
标签: asp.net asp.net-mvc-4