ASP.NET MVC 3默认包含名称空间System.ComponentModel.DataAnnotations

时间:2012-02-28 09:24:30

标签: c# asp.net-mvc-3 namespaces

这可能是一个非常愚蠢的问题,但我似乎找不到答案。在我的模型类中,我总是需要添加几行using语句 - 例如

using System.ComponentModel.DataAnnotations

有没有办法在每个模型类中自动包含该命名空间,所以我不必每次都输入它?

由于

3 个答案:

答案 0 :(得分:3)

您的问题是similar to this one该问题的答案是您有4种选择:

  • 手动编辑
  • 和它一起生活
  • change the class template(或导出第二个类模板)
  • 在子目录外创建文件,然后将其拖入

see more comments on the question

答案 1 :(得分:0)

要实现这一点,您需要创建自定义Visual Studio项目模板:

How to create a Visual Studio Item Template

答案 2 :(得分:0)

此命名空间用于验证属性。我倾向于在我的班级中写出一个属性,并添加一个属性,例如RequiredAttribute

我输入[Required,然后d Visual Studio在该行的底部放置一个小方块。按 Ctrl + ,您将获得一个上下文菜单,为您添加所需的using语句。因此,您无需手动输入。