8,497
社区成员
发帖
与我相关
我的任务
分享
public ActionResult Index()
{
var QuestionInfoList = db.QuestionInfoes.Include(a => a.Q_Category).Include(a => a.Q_Type);
return View(QuestionInfoList.ToList());
}
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.Q_Type.Q_TypeName)</td>
<td>@Html.DisplayFor(modelItem => item.Q_Category.Q_CategoryName)</td>
<td>
@Html.DisplayFor(modelItem => item.Q_Title)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Q_Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Q_Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Q_Id })
</td>
</tr>
}
[Table("Question")]
public class QuestionInfo
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Q_Id { get; set; }
[Display(Name = "Q_Title")]
public string Q_Title { get; set; }
public QuestionType Q_Type { get; set; }
public QuestionCategory Q_Category { get; set; }
}
[Table("QuestionType")]
public class QuestionType
{
[Key]
public int Q_TypeID { get; set; }
public string Q_TypeName { get; set; }
}
[Table("QuestionCategory")]
public class QuestionCategory
{
[Key]
public int Q_CategoryID { get; set; }
public string Q_CategoryName { get; set; }
public int Q_CategoryParentID { get; set; }
}