Tech Off Thread

2 posts

Please confirm these facts about MVC 4

Back to Forum: Tech Off
  • User profile image
    Sathyaish Chakravarthy

    I did MVC 2 two years ago. I am now using MVC 4 and would like to confirm a few things (StackOverflow is down for maintenance just now for about an hour).

     

    1. In MVC 4, we do not need to create a ModelMetadata class to annotate with data annotations for data validation. We may simply annotate the model classes themselves.

      In other words, if we are using the EDM generator to generate a model and corresponding classes for us, then we may create a new set of partial classes with the same names and use data annotation attributes on those partial classes themselves.

      We do not need to create a new type of model metadata class and decorate *that* class with data annotation/attributes, like here: http://www.asp.net/mvc/tutorials/older-versions/models-%28data%29/validation-with-the-data-annotation-validators-cs

    2. For data annotations to work, we need a reference only to System.ComponentModel.DataAnnotations and not to Microsoft.Web.Mvc.DataAnnotations.
    3. We do not need to instantiate the default model binder in the Application_Start event in the Global.asax file.

    Could you please confirm if my understanding is correct?

  • User profile image
    ldiego08

    All of those affirmations are correct. The MVC codebase has changed a lot since version 2. All of the model validation is made by using attributes from the System.ComponentModel.DataAnnotations namespace. 

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.