Lambda expression in @Html.DisplayFor(modelItem => item.FirstName)

I found a very good explanation about the Lambda expression in @Html.DisplayFor(modelItem => item.FirstName), see Link below.


As the author wrote, a lambda expression is a way to write an anonymous function. As a summary you can find here the lambda expression and its anonymous function it could be translated logically.

Common lambda expression

(x => x.Name)

>>>>>> translates to >>>>>>

string Function(Data x) 
 return x.Name 

Lambda expression without left-side parameter

(() => someVariable)

>>>>>> translates to >>>>>>

string Function() 
 return someVariable; 

Lambda expression in @Html.DisplayFor(model => item.FirstName)

model => item.FirstName

>>>>>> translates to >>>>>>

string Function(Model model) 
 return item.FirstName; 


Here you find the complete post: I want to understand the lambda expression in @Html.DisplayFor(modelItem => item.FirstName)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.