Umbraco MVC localised data annotations

So in MVC you decorate your model with data annotations things like

[Display("Email Address")]
[Required]
public string EmailAddress {get; set;}

With these attributes you pass in some text or you can use a .net resource. In that case you give it assembly and key

[Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)]

It would be nice if we could use the Umbraco dictionary as well. So I have created my own classes so for the display and required attributes i have


[UmbracoDisplayLocalised("Email")]
[Email("InvalidEmail")]
[UmbracoLocalisedRequired("InvalidEmail")]
public string EmailAddress {get; set;}

What I pass in is Umbraco dictionary key so now my model when rendered in view has localised labels. I also have a custom build of the excellent data annotations project which also reads from the Umbraco dictionary.

I have sent it to Lee Kelleher Sir uComponents to have a play. It may appear in there or I will release as a separate project on our. My source code is available  on github

https://github.com/ismailmayat/MvcUmbracoDataAnnotations

Advertisements

14 thoughts on “Umbraco MVC localised data annotations

  1. ismailmayat says:

    Moran,
    You should not need to. I am not doing any caching at my end so it should swap out. Try adding a dictonary call in a template then swap language see if that swaps out.

    It it does not then raise an issue on our as it maybe a bug?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s