views:

21

answers:

1

I'm quite new to asp.net mvc, and right know I'm trying to find out a good practise to do input validation.

In the project we're going to use entity framework, where you can add data annotations to properties in the following way:

[Required(ErrorMessage = "Please enter a product name")]
[Column]
public string Name { get; set; }

This is quite nice, however we have a multi language website (like most websites), so we can't only show the error messages in English. What can be a way to solve this? Can I change this errormessage @runtime, depending on the user's language? Should I use Jquery client side validation?

Thanks for the input.

Update I've tried the code on the website of Phil Haack This will do the trick with static resources however, we use resources that come from a database not static resources.

If I fill in the following for the dataannotations:

   [MetadataType(typeof(IncidentsMetaData))]
public partial class INCIDENTS
{
    private class IncidentsMetaData
    {
        [Required(ErrorMessageResourceType = typeof(CustomResourceProviders.DBResourceProviderFactory),
            ErrorMessageResourceName="1277")]
        public string SUBJECT { get; set; }
    }
}

Then I get the following error: The resource type 'CustomResourceProviders.DBResourceProviderFactory' does not have an accessible static property named '1277'.

Of course there is no such property, it should be accessed by a function. Any idea what I could do about this? tnx

A: 

Phil Haack has written a good blog post that covers how to do this. Essentially it is much the same except you use resource files to provide the messages.

[Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = Required")]
public string MyProperty{ get; set; }
Andy Rose
Thanks for the answer.
denappel
I've edited the question, because although the answer is helpfull, it doesn't solve my problem completely
denappel