ASP MVC 2 : Custom display of a required form element based on ModelMetaData
- by Nigel
I have an MVC 2 application that utilises forms. The required fields within the form are set using attributes that update the model metadata. The form fields are created using the MVC HtmlHelper method : Html.EditorFor.
This works fine so far as validation is concerned, but it seems that by default the required fields are not displayed to the user (for example by appending a * to the control).
If I wanted to provide some custom means of displaying this fact to the user (lets immagine I want to change the background colour of the edit control for example), where is the best place to do it. Would I need to create a custom html helper to replace EditorFor? I tried but it seemed difficult to gain access to the metadata for the correct property. I already have a custom ModelMetaDataProvider so there is no problem adding it there if that is the correct place.