0
我利用模型验证功能是这样的:依赖于ASP.NET核心应用使用模型验证
[StringLength(60, MinimumLength = 3)]
[Required]
但是当我启动应用程序,我得到这样的:
Author.cs(8,6): error CS0246: The type or namespace name 'StringLengthAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(8,6): error CS0246: The type or namespace name 'StringLength' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(9,6): error CS0246: The type or namespace name 'RequiredAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(9,6): error CS0246: The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(8,23): error CS0246: The type or namespace name 'MinimumLength' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(11,6): error CS0246: The type or namespace name 'StringLengthAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(11,6): error CS0246: The type or namespace name 'StringLength' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(12,6): error CS0246: The type or namespace name 'RequiredAttribute' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(12,6): error CS0246: The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)
Author.cs(11,23): error CS0246: The type or namespace name 'MinimumLength' could not be found (are you missing a using directive or an assembly reference?)
我找不到我丢失的包。我的猜测是Microsoft.AspNetCore.Mvc.DataAnnotations
,但似乎并非如此。
那么我需要什么依赖?
似乎是正确的,你有没有进口正确的命名空间?应该是'使用System.ComponentModel.DataAnnotations'或者'使用System.ComponentModel.Annotations'。只要在错误上点击'Ctrl' +'.'来让VS建议你一个命名空间 – Tseng
是的,我忘了'使用'!非常感谢 – vanthome
我发表了评论作为答案 – Tseng