asp.net mvc - ASP MVC 2 : Custom display of a required form element based on ModelMetaData -


I have an MVC 2 application that uses the form that determines the required field within the form using those attributes Which are updated. Form fields are created using the MVC HtmlHelper method.

Validation is concerned, but it works properly, but it seems that by default the required fields are not displayed to the user (for example * to control).

If I wanted to give the user some custom methods of displaying this fact (for example I want to change the background color of the editing control), where is the best place to do this? Do I need to create a Custom HTML Assistant to replace the EditorFor? I tried but found it difficult to access metadata for the right property. I already have a custom model. MetaataProvider therefore there is no problem if this is the right place.

Instead of a custom assistant, you probably want a custom template. For more information on how to find out more about template designing Broad Wilson, your custom template will mimic the standard template, except that you have a marker for the required fields, but the basic idea is that To create a viewer control in the shared / editor templates (and shared / display templates) folders typed for your model. You can then use EditorFor and DisplayFor and specify the template name to use, although I think it will also pick up your template if it is strictly written in your model.


Comments