Rick
Rick

Reputation: 85

ASP.NET MVC 3 include namespace System.ComponentModel.DataAnnotations by default

This is probably a really silly question, but I can't seem to find an answer for it. In my model classes, I always have to add in a couple of lines of using statements - for example

using System.ComponentModel.DataAnnotations

Is there any way to have that namespace included automatically in every model class so I don't have to type it in every time?

Thanks

Upvotes: 1

Views: 1196

Answers (3)

Graham Clark
Graham Clark

Reputation: 12966

This namespace is used for the validation attributes. I tend to write out a property in my class, and add an attribute, e.g. RequiredAttribute.

I type [Required, and after the d Visual Studio puts a little square at the bottom of the line. Hit Ctrl + . and you'll get a context menu that will add the required using statement for you. So you don't ever have to type it out by hand.

Upvotes: 0

robasta
robasta

Reputation: 4701

Your question is similar to this one The answer in that question is you have 4 options:

  • edit it manually
  • live with it
  • change the class template (or export a second class template)
  • create the file outside the sub-directory, then drag it in

see more comments on the question

Upvotes: 3

Marcin
Marcin

Reputation: 3262

To achieve that you will need to create custom visual studio item template:

How to create a Visual Studio Item Template

Upvotes: 0

Related Questions