MvcScaffolding Enhancement - DisplayAttribute Support

Steve Sanderson has an excellent blog series, describing his MvcScaffolding NuGet Package.

For example, I was reading his post, describing how to override the T4 Template output generated by MvcScaffolding:

http://blog.stevensanderson.com/2011/04/06/mvcscaffolding-overriding-the-t4-templates/

I wanted to add support for any DisplayAttribute DataAnnotations on my Model classes, in those parts of the Razor views not handled by HtmlHelpers.

For example, labels for dropdown lists for RelatedEntities were based on the RelatedEntity Name property value.

With a small additional amount of logic, any associated DisplayAttribute Name can be obtained and used as an override.

The attached ZIP file contains the results of my experiments.

To use in an existing MVC3 application, simply unzip the contents of the attachment and include the CodeTemplates folder in the MVC3 Project, as a child of the root folder. Using this well-known location, MvcScaffolding will use these replacement templates instead of the defaults.

No Comments