What's the effective difference between using a lambda expression and a direct object reference in a strongly typed view? Obviously, lambda expressions are much longer, but they also seem to have some magic I don't yet grasp.
Here is an example... In this case, both item.Title lines print the title of the post. You can imagine why I prefer the shorter one...
@foreach (var item in Model.Posts)
{
@item.Title
@Html.DisplayFor(modelItem => item.Title)
}
However, in this case (accessing an object referenced by the object), only the lambda works. I get an "Object reference not set" error with the first line.
@foreach (var item in Model.Posts)
{
@item.User.UserName
@Html.DisplayFor(modelItem => item.User.UserName)
}
If anyone could illuminate what's going on here for a novice developer, I'd certainly learn something.