This is microsoft's scaffolding code for the action Details of the entity MyEntity:
public async Task<ActionResult> Details(Guid? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
MyEntity myEntity = await db.MyEntities.FindAsync(id);
if (myEntity == null)
{
return HttpNotFound();
}
return View(myEntity);
}
Now let's say I want to display the name of the owner of this entity in details.cshtml, if I write the following code:
<dt>
Owner
</dt>
<dd>
@Html.DisplayFor(m => m.User.FullName)
</dd>
User shows up as null, even after trying to access Model.User to trigger the lazy loading.
Edit: Adding the model as requested
public class MyEntity
{
public Guid? Id { get; set; }
public string Name { get; set; }
public ApplicationUser User { get; set; }
}