Using an EditorEntryFor helper makes the code DRYer and opens new possibilities, such as automatic indication of required fields. A small addition in one helper method will mark all required fields in entire MVC web application.

It’s more or less standard to indicate required fields in a form with a red * next to the label. Entering them one by one in the markup is tedious. Adding them to the description text is outright wrong and will look bad if the description is used in other places, such as validation messages.

They shouldn’t need to be handled at all, since the metadata already contains a property indicating if the field is required or not. If all form entries are created in the same way as I showed in the DRYing MVC Forms with an EditorEntryFor Helper post it’s easy to automatically add a required marker whenever a form field is required.

Instead of calling LabelFor directly, I’ve created an own helper method that checks the IsRequired flag on the metadata.

First the metadata is looked up based on the expression using standard ASP.NET MVC methods. Then the IsRequired field is set. It is automatically updated based on data type and if there is a [Required] attribute. Any non-nullable value types are always required. Nullable value types and reference types are only required if there is a [Required] attribute. If the field is required, a span with a single * inside it is added right after the label.