@Html.EditorFor(m => m) lambda syntax in MVC

前端 未结 4 1430
野趣味
野趣味 2021-02-05 16:08

I\'m just learning C# and MVC, and trying to understand some examples.

@Html.EditorFor(m => m)

Eventually I figured out that \'=>\' is the l

4条回答
  •  [愿得一人]
    2021-02-05 16:20

    Think of the => operator as meaning "goes to", so (m => m) means "m goes to m", another way of saying you get back the same thing m.

    In your example, @Html.EditorFor(m => m), m is an anonymous input parameter to the lambda expression m => m, which is an argument of the extension method EditorFor. As you noted in your question, none of the overloads for this method take less than a single parameter; this is because it is an Extension Method and the first parameter indicates the type it extends. The second parameter is an Expression, and you can use lambda expressions for these.

提交回复
热议问题