0

How does Microsoft MVC know that the name of the property is "Phone" since we have only the object instance and one of it's properties' value?

<%: Html.TextBoxFor(x => x.Phone) %>

2 Answers 2

3

You haven't got the property's value - you've got an expression tree which tells you how to obtain the value from an item. That expression tree can be analyzed by the framework to find the property name.

Now if it were

<%: Html.TextBoxFor(x.Phone) %>

then that would genuinely be just getting the value... but the lambda expression is being converted into an expression tree by the C# compiler.

Sign up to request clarification or add additional context in comments.

1 Comment

Nice! Does all lambda expressions work this way or this is a special case?
3

They are using this 'trick'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.