I have created a custom editor template for DateTimeOffset:
@model DateTimeOffset
<div>
@Html.LabelFor(m => Model)
@Html.TextBoxFor(m => Model)
</div>
It is used via standard API:
@Html.EditorFor(m => m.DateTimeOffsetField)
I have noticed the label that gets created has text Model:
<label for="DateTimeOffsetField">Model</label>
Also, Required field validator refers to the generated field as “Model” in the error message:
Please enter Model
I assume that because the internal metadata provider is no longer aware of the original model and just knows about the new DateTimeOffset model.
How should this be handled?
Is there a different overload I can use or should I use a lower-level API (e.g. @Html.Label)?
You should pass
m => m, using the parameter instead of theModelproperty.