MetadataType attribute

Sep 16, 2010 at 5:13 PM
Edited Sep 16, 2010 at 5:16 PM

In my opinion, the use of MetadataType attribute on the model classes is redundant and can be removed as they are associating the Model classes to themselves.

Any thoughts? Is there any specific reason why the models are decorated with the Metadata attribute this way?


Sep 17, 2010 at 9:27 AM

For client validation

Sep 17, 2010 at 3:21 PM

Thanks Stuhin for the reply. I am still a beginner learning MVC by looking through the various projects on codeplex.

I may be wrong here but I am specifically asking about the attribute and not the actual metadata on the model.

For example, in your code you use

    [MetadataType(typeof(ArticleSettingModel))]  <-- This line is not necessary
    public class ArticleSettingModel

which means that the metadata for class ArticleSettingModel is defined in class ArticleSettingModel (which is itself). Try removing that from your code and you will see that validation will still work.

In my understanding the MetadataType attribute is really only useful for attaching metadata to EF entities (There may be other uses which I do not know) but since you do POCO and then derive the ViewModels on which you attach the metadata, it is unnecessary.


Sep 17, 2010 at 3:58 PM

Thank you for the test cheedep!

In this case, really MetadataType excess.

Sep 18, 2010 at 7:54 PM

Without Metadata Validation of the page is reloaded!

client validation to verify the data on the client side (browser)

Sep 19, 2010 at 6:39 AM

what do you mean Validation is reloaded? Is it not a desired thing.

We do client side validation on input screens and so if the user is still on the edit page we should have the client validation functions loaded too.


Can you explain what you observed a little more elaborately so that I can test it. Thanks so much.

Sep 19, 2010 at 7:25 AM

Yes, indeed Metadata now appears on the page without the wrap class.

(The question of where she's taken if the class is not wrapped)