ASP.Net MVC3 - Custom data annotation to force to upper-case -


i'd create custom data annotation force data entered upper-cased. if user types in lower-case, should automatically (and silently) converted upper-case. not validation issue.

i'd this:

public class address {     public string address {get; set;}     public string city {get; set;}      [forceuppercase]     public string state{get; set;}  } 

for example, when using @html.editorfor(x => x.state) i'd html that's created take care of of me - don't want have write jquery calls change data or force in particular class name.

i wrong, don't see way of doing attribute. can use backing field property, so:

public class address {     private string _state;      public string address {get; set;}     public string city {get; set;}      public string state     {         { return _state; }         set { _state = value.toupper(); }     } } 

sure, uglier, works.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -