Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:22:16+00:00 2026-06-17T08:22:16+00:00

I found this Related Topic , but it failed to answer my question. When

  • 0

I found this Related Topic, but it failed to answer my question.

When automatically creating a strongly typed view, lets say with a List scaffolding template, I will get something roughly like this:

@model IEnumerable<Test.Models.abc>
<table>
    <tr>
    <th>
        @Html.DisplayNameFor(model => model.ID)
    </th>
</tr>

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.ID)
    </td>
</tr>
}
</table>

I understand @Html.DisplayNameFor(model => model.ID) completely, but not @Html.DisplayFor(modelItem => item.ID).

What is the purpose of modelItem? Replacing it with any arbitrary text will result in a functional web page. It seems that modelItem is just a throwaway word. I guess my real question is why doesn’t this work?

@Html.DisplayFor(item => item.ID)

Edit

A good point was brought up in the comments. It seems you are also able to change model to anything so long as you change it on both sides of the lambda expression:

@Html.DisplayNameFor(abc => abc.ID)

A side question would be: How does the @model statement at the top affect the functions below? I had previously thought model referenced the @model expression in order to figure out the display name via the class, but the page still works after the mentioned changes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:22:18+00:00Added an answer on June 17, 2026 at 8:22 am

    It does not work because item is already declared in outer scope in foreach.

    @foreach (var item in Model).

    The reason why modelItem lambda is not used is because of that iteration of IEnumerable. If there would be Test.Models.abc as model instead of IEnumerable, then would that lambda does matter and the code of DisplayFor would change to @Html.DisplayFor(m => m.ItemId).

    Update

    @model IEnumerable<Test.Models.abc> just declares that this view is strongly typed, with type of IEnumerable<Test.Models.abc> – in your case. That means that view property this.Model (not model) is of type IEnumerable<Test.Models.abc> – and also that model of that type should passed into this view. model in example above is just expression variable – it has scope just for that expression. You can change it’s name to any unprotected legal variable name that was not already used in outer scope (that’s why it should not be named Model, because it would hide the Model property already declared in view).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title is my question. I already found a topic related to this here
Very much related to my previous question , but I found this to be
I found this related question: How do I use composition with inheritance? I would
So, i recently found this term related somehow to neural networks, but I don't
I have found this Related entry and a few others but I have not
I have searched all the questions related to this topic but i didnt find
This is a follow up on a related topic found here https://stackoverflow.com/questions/1987485/conditionally-assign-c-var-as-elegant-as-it-get s if
I found a few questions related to this, but none that I could figure
Simple question, but I couldn't find any related topics that match this exact scenario.
I’ve previously asked a question related to this topic as well and with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.