Reputation: 435
We're currently migrating an existing application to ASP.NET MVC 3. We're reusing the database schema which contains all of our resources in the database rather than resx files.
We have a ResourceProvider that acts as a facade around the resource repository which has a method that accepts a Key and returns the specified resource in the users default culture.
We're going to want to leverage MVC's model DataAnnotations to bind our model to our razor views providing labels and validation etc.
My question is how do we achieve this so that it can talk to our ResourceProvider?
Do I need to implement a custom DataAnnotationsModelMetadataProvider? or is there a better/easier way to achieve this?
Any ideas are appreciated.
Upvotes: 1
Views: 3157
Reputation: 101150
I've got a ready solution (that works with model and validation localization) which you can use: http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/
All you need to do is to implement the IStringProvider interface to read from your own database instead.
Update
I've now written an article about it.
Upvotes: 2
Reputation: 10221
I think this is what you are looking for, it's MVC2 targeted but should just as well work with MVC3 / MVC4:
http://carrarini.blogspot.com/2010/08/localize-aspnet-mvc-2-dataannotations.html
We did the same thing and in the end we went with the T4 Template if I'm not mistaken.
Upvotes: 1