Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Created November 8, 2013 17:09
Show Gist options
  • Save gabrieljoelc/7374265 to your computer and use it in GitHub Desktop.
Save gabrieljoelc/7374265 to your computer and use it in GitHub Desktop.
For defaulting view model property display names to space delimited versions of the property name. From http://trycatchfail.com/blog/post/Building-Nice-Display-Names-From-Pascal-Case-View-Model-Names-in-ASPNET-MVC-3.aspx. See https://gist.github.com/gabrieljoelc/7374242 for the string::ToStringWithSpaces() method.
public class PascalCaseToDisplayNameFilter : IModelMetadataFilter
{
public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable<Attribute> attributes)
{
if (!string.IsNullOrEmpty(metadata.PropertyName) && !attributes.OfType<DisplayNameAttribute>().Any())
{
metadata.DisplayName = metadata.PropertyName.ToStringWithSpaces();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment