I think that the usage of @Html.LabelForModel()
should be explained in more detail.
The LabelForModel Method returns an HTML label element and the property name of the property that is represented by the model.
You could refer to the following code:
Code in model:
using System.ComponentModel;
[DisplayName("MyModel")]
public class MyModel
{
[DisplayName("A property")]
public string Test { get; set; }
}
Code in view:
@Html.LabelForModel()
<div class="form-group">
@Html.LabelFor(model => model.Test, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Test)
@Html.ValidationMessageFor(model => model.Test)
</div>
</div>
The output screenshot: