Localization in Range attribute



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:

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

And then in language file:

            Stor innehållsyta
            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?


Mar 14, 2016 9:08

In stead of

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


[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.


Mar 14, 2016 10:06

Works like a charm. Thanks Mark!


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.