Created
November 8, 2013 17:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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