Localization in Range attribute

Vote:
 

Hello!

How should the path to the resource string containing error messages should be passed to Range attribute in int properties?

I have declared the property like this:

[Display(
           GroupName = SystemTabNames.Content,
           Order = 150)]
        [Range(1,5, ErrorMessageResourceName = "/contenttypes/icontentdata/errormessages/invalidamountnews")]
        public virtual int AmountItems { get; set; }


And then in language file:


    
      
      
        
          
            Nyckelord
          
          
            Beskrivning
          
          
            Stor innehållsyta
          
          
            Brödtext
            Brödtexten visas i sidans centralyta. Via XHTML-editorn kan du infoga exempelvis text, bilder och tabeller.
          
          
        
        
          Antalet att visa kan inte vara mindre än 0
        
      
    

This is not working and the property view for the pages of the page type loads forever, so I guess I'm passing the wrong path to the attribute. Can't find any good example either.

Does anybody have any suggestions?

/Kenia

#145831
Mar 14, 2016 9:08
Vote:
 

In stead of

[Range(1,5, ErrorMessageResourceName = "/contenttypes/icontentdata/errormessages/invalidamountnews")]

use

[Range(1,5, ErrorMessage = "/contenttypes/icontentdata/errormessages/invalidamountnews")]

However this will still not display your error message all the time.
If you enter an invalid value like "abc" you will see your error message.
If you enter a valid integer that is out of range you will see the default error message.

I haven't found a solution for this other than writing my own validator.

/Mark

#145835
Mar 14, 2016 10:06
Vote:
 

Works like a charm. Thanks Mark!

/Kenia

#145840
Mar 14, 2016 10:38
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.