【问题标题】:Validation of method in .cs file in asp.net在 asp.net 中验证 .cs 文件中的方法
【发布时间】:2014-05-20 10:11:32
【问题描述】:

网... 我在给定链接中的教程的帮助下制作了一个简单的 MVC 项目:

http://www.codeproject.com/Articles/486161/Creating-a-simple-application-using-MVC

我在这个特定阶段遇到了错误。

现在让我们对字段应用验证:

Error   2   The type or namespace name 'DisplayName' could not be found (are you missing a using directive or an assembly reference?)   
C:\Users\sword\Documents\Visual Studio 2012\Projects\MyCalculatorSrevice\MyMvc1\MyMvc1\Models\UserModels.cs

我搜索了它,但找不到任何东西来消除这个错误。

帮帮我

感谢

【问题讨论】:

  • 您是否添加了对 System.ComponentModel.DataAnnotations 的引用,听起来好像缺少 Display 属性
  • 我知道你已经指出了代码,但是代码的一个小sn-p会让这里的人更容易提供帮助-无需先去其他地方。

标签: c# asp.net validation asp.net-mvc-4 methods


【解决方案1】:

确保:

  1. 您已经引用了 System.ComponentModel 程序集
  2. 您已在 UserModel.cs 文件中通过using System.ComponentModel; 导入注释。

希望对你有帮助

【讨论】:

    【解决方案2】:

    您实际上缺少对DataAnnotations 的引用。尝试在引用之间添加以下行,它将开始工作。

    using System.ComponentModel.DataAnnotations;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-02
      • 2016-10-11
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 2022-06-16
      相关资源
      最近更新 更多