c830
c830

Reputation: 514

Html.DisplayFor syntax

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>

Upvotes: 1

Views: 3501

Answers (2)

RickAndMSFT
RickAndMSFT

Reputation: 22850

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?

Upvotes: 4

Kris Ivanov
Kris Ivanov

Reputation: 10598

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)))

Upvotes: 1

Related Questions