ASP MVC 2 : Custom display of a required form element based on ModelMetaData
Posted
by Nigel
on Stack Overflow
See other posts from Stack Overflow
or by Nigel
Published on 2010-05-17T15:08:03Z
Indexed on
2010/05/17
15:10 UTC
Read the original article
Hit count: 325
asp.net-mvc
|asp.net-mvc-2
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.
© Stack Overflow or respective owner