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

  • Home
  • SEARCH
  • 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 9252149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:52:22+00:00 2026-06-18T10:52:22+00:00

I have a question that probably is quite basic but I don’t really get

  • 0

I have a question that probably is quite basic but I don’t really get it. So here it comes.

If I have a view template file ( .cshtml ) and have a codeline like this:

@Html.DisplayFor(m => m.CurrentPage.MainBody)

If I look on the declaration for DisplayFor it looks like this:

public static MvcHtmlString DisplayFor<TModel, TValue>(this HtmlHelper<TModel> html,      Expression<Func<TModel, TValue>> expression);

So this is an extension method that takes an Expression parameter but TModel and TValue seems to be generic ( and apparently you can send in a lambda expression to an Expression).

How can the lambda expression here ( m => m.CurrentPage.MainBody ) know what m is?

If I have a lamdba expression like this:

int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int oddNumbers = numbers.Count(n => n % 2 == 1);

Then the context for (n => n % 2 == 1) is logic, the lamdba expression is used to evaluate each element in numbers.

But in the case above with @Html.DisplayFor(m => m.CurrentPage.MainBody) what is the context here? What is m referring to? Is that somehow “magically” connected to the @model in this particular view? ( which in this case is@model PageViewModel<ArticlePage> “).

So to sum up, what is m referring to in the expression ( m => m.CurrentPage.MainBody ) ? Is it assumed somehow that it is refering to the model provided in the view via the @model?

  • 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-18T10:52:24+00:00Added an answer on June 18, 2026 at 10:52 am

    How can the lambda expression here ( m => m.CurrentPage.MainBody ) know what m is?

    The Html.DisplayFor helper is defined like this:

    public static MvcHtmlString DisplayFor<TModel, TValue>(
        this HtmlHelper<TModel> html, 
        Expression<Func<TModel, TValue>> expression
    )
    {
        ...
    }
    

    Notice how this helper can only be invoked on a strongly typed HtmlHelper<TModel>. If you do not have a strongly typed view with a model you cannot use the Html.DisplayFor helper because Html on which you are invoking this extension method is simply HtmlHelper and not HtmlHelper<TModel>.

    So inside your view when you have a model:

    @model MyViewModel
    

    The Html property is of type HtmlHelper<MyViewModel> so the DisplayFor helper knows about your model.

    Basically when you have a strongly typed view, Html.DisplayFor(m => m.CurrentPage.MainBody) is a shortcut for Html.DisplayFor<MyViewModel, TheTypeOfYourMainBodyProperty>(m => m.CurrentPage.MainBody) where the compiler could infer the generic arguments from the context and you don’t need to write them explicitly.

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

Sidebar

Related Questions

This is probably a basic html/css question... I have a simple one-button form that
I have a question that may be quite naive, but I feel the need
I have a probably quite basic question: I am currently setting up a database
There is probably a quite logical explanation to this, but I have a question.
This is probably a multi-part question. Background: we have a native (c++) library that
I have a question that I just don't feel like I've found a satisfactory
I have a question that I'm ashamed to ask, but I'm going to have
I have a question that may sound odd, but being somewhat of a newbie,
This question is probably quite different from what you are used to reading here
That question probably sounded extremely confusing, but it's difficult to describe what I want

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.