MetadataType attribute

Sep 16, 2010 at 4:13 PM
Edited Sep 16, 2010 at 4: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?

Thanks.

Coordinator
Sep 17, 2010 at 8:27 AM

For client validation

Sep 17, 2010 at 2: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.

 

Coordinator
Sep 17, 2010 at 2:58 PM

Thank you for the test cheedep!

In this case, really MetadataType excess.

Coordinator
Sep 18, 2010 at 6: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 5: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.

Coordinator
Sep 19, 2010 at 6: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)