Going from ASP.NET 2.0 (VB) to MVC 3 (C#), I'm very confused about the syntax being used for the View.
@Html.LabelFor(m => m.UserName)
Where did that m come from? My only guess is that it represents the model that is being passed into the view. I tried changing the m to c and it still works fine.
Is the part of the syntax that involves the "=>" more of a MVC, C#, or Razor element?
Where did that
m
come from?
It's the parameter in a lambda expression.
My only guess is that it represents the model that is being passed into the view. I tried changing the m to c and it still works fine.
That's because the name doesn't matter. It's just a parameter name, it doesn't actually refer to any existing variable.
Is the part of the syntax that involves the "=>" more of a MVC, C#, or Razor element?
It's C#, but LabelFor
uses what the compiler translates m => m.UserName
into to extract what it needs to build up the label.
This is a very deep an intricate subject. I suggest that you find a book that you're comfortable with (e.g., C# in Depth is very good on this subject) to understand more. You want to read about lambda expressions and expression trees.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With