Please, can anyone tell me what the meaning of => operator in Html helper syntax.
Eg: @Html.TextBoxFor(m => m.UserName)
Please, can anyone tell me what the meaning of => operator in Html helper syntax.
Eg: @Html.TextBoxFor(m => m.UserName)
m => m.Username
is equivalent to providing a method, something like
string GetUserName(TypeOfModel m)
{
return m.UserName;
}
However, because TextBoxFor takes an Expression, it is able to 'parse' the lambda and is able to infer that the name of the TextBox input should be 'Name' (viz the property scraped off the model). This is important and 'intuitive', since the MVC ModelBinder will then be able to map "Name" to a property or parameter when it is next sent back to a controller.