在.NET视图中找到该表达式的确切含义是什么?

时间:2018-10-24 08:59:29

标签: c# asp.net .net asp.net-mvc

我在 .NET 中非常陌生,对于在某些视图中发现的这些表达方式,我有以下疑问。

我有这样的看法:

@model Vidly_v2.ViewModels.NewCustomerViewModel
@{
    /**/

    ViewBag.Title = "New";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<h2>New Customer</h2>

@using (Html.BeginForm("Save", "Customers"))
{
    <div class="form-group">
        @Html.LabelFor(m => m.Customer.Name)
        @Html.TextBoxFor(m => m.Customer.Name, new { @class = "form-control" })
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.Customer.Birthdate)
        @Html.TextBoxFor(m => m.Customer.Birthdate, "{0:d MMM yyyy}", new { @class = "form-control" })
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.Customer.MembershipTypeId)
        @Html.DropDownListFor(m => m.Customer.MembershipTypeId, new SelectList(Model.MembershipTypes, "Id", "Name"), "Select Membership Type", new { @class = "form-control" })
    </div>
    <div class="checkbox">
        <label>
            @Html.CheckBoxFor(m => m.Customer.IsSubscribedToNewsletter) Subscribed to Newsletter?
        </label>
    </div>
    @Html.HiddenFor(m => m.Customer.Id)
    <button type="submit" class="btn btn-primary">Save</button>
}

如您所见,我正在使用此模型对象

@model Vidly_v2.ViewModels.NewCustomerViewModel

在此视图中,我以这种方式使用此模型对象:

@Html.LabelFor(m => m.Customer.Name)
@Html.TextBoxFor(m => m.Customer.Name, new { @class = "form-control" })

只需呈现此HTML代码:

<label for="Customer_Name">Name</label>
<input class="form-control" data-val="true" data-val-length="The field Name must be a string with a maximum length of 255." data-val-length-max="255" data-val-required="The Name field is required." id="Customer_Name" name="Customer.Name" value="" type="text">

与此模型对象属性有关。

我的疑问是:什么是确切的表达?

m => m.Customer.Name

我认为 m 表示模型对象(如果我做错了断言,请纠正我),但我无法理解该表达式的含义和确切用法。