1

I am studying a MVC sample. I couldn't wrap my head around the syntax of "@Html.DisplayFor(modelItem => item.FirstName)". In the following code, I understand modelItem is what passed into the view which is an object of IEnumerable<Runner>. I am not understanding what does "modelItem => item" mean. In order word, How do you translate this lambda back to normal c# syntax? Thanks

@model IEnumerable<Runner>

<div id="Finishers">
   <h4>Finishers</h4>
   <ul id="finihers_female">
     @foreach (var item in Model) {
     <li>
            @Html.DisplayFor(modelItem => item.FirstName) 
            @Html.DisplayFor(modelItem => item.LastName)
            @Html.DisplayFor(modelItem => item.Gender)
            @Html.DisplayFor(modelItem => item.FinishedTime)
     </li>}
  </ul>
c830
  • 514
  • 1
  • 7
  • 15

2 Answers2

4

My MSDN document DisplayExtensions.DisplayFor Kris Ivanov listed doesn't do anything to answer the question. You need to read about Lambda expressions. This SO thread on exactly this question might help. Can folks add links to their favorite Lambda tutorials?

Community
  • 1
  • 1
RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
  • I wonder why this answer was downvoted. It exactly answers the question. The OP has troubles with understanding lambda expressions and expression trees in C# and this answer points it to some useful articles on learning it. I have always thought that one should first learn C# and then jump into some specific application development technology such as ASP.NET, WPF, ... – Darin Dimitrov Dec 26 '11 at 08:35
1

it is Expression(Of Func(Of TModel, TValue)), here some info for you DisplayExtensions.DisplayFor(Of TModel, TValue) Method (HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TValue)))

Kris Ivanov
  • 10,476
  • 1
  • 24
  • 35