您正在撰写文章页面并拥有一个带有ApplicatonUser属性的文章模型。
public class postModels
{
public int ID { get; set; }
public postModels parentPost { get; set; }
[StringLength(255)]
[Required]
public string title { get; set; }
public string post { get; set; }
public ApplicationUser appUser { get; set; }
public DateTime created { get; set; }
public DateTime lastEdited{ get; set; }
}
在我的剃刀视图中我试试这个
@foreach (var item in Model)
<div class="row">
<div class="col-md-2">
@Html.DisplayFor(modelItem => item.created)
<br />
@Html.DisplayFor(modelItem => item.lastEdited)
<br />
@Html.DisplayFor(ModelItem => item.appUser.NickName)
<br />
<br />
<br />
<br />
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</div>
<div class="col-md-10">
<div class="row">
<div class="col-md-12"><h1>@Html.DisplayFor(modelItem => item.title)</h1></div>
<div class="col-md-12">@Html.DisplayFor(modelItem => item.post)</div></div>
</div>
</div>
除ApplicationUer属性之外的所有内容的输出都有效.. 感谢您的帮助和兴趣:)