I am new to C# and I'm not sure I understand this piece of code:
@Html.DisplayNameFor(model => model.isAlive)
From what I searched online, the lambda operator would be shorthand for a function such as
parameter => expression
.
- Is this what is being used here?
- If so, is the function being called automatically since it has no name?
- Is a model object being implicitly passed in the 'model' parameter?
This is the full code:
@model IEnumerable<FirstMVC.Models.PersonModel> //retrieving the passed list (people) object, it becomes IEnumerable
@{
ViewBag.Title = "ListPeople";
}
<h2>ListPeople</h2>
<p> <!--Here, only 2 params because it's assuming using PeopleController-->
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th><!--Displays column NAMES, notice DisplayNameFor-->
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.Age)
</th>
<th>
@Html.DisplayNameFor(model => model.isAlive)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td> <!--Displays row VALUES-->
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
<td>
@Html.DisplayFor(modelItem => item.isAlive)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>