【发布时间】:2015-04-25 05:25:07
【问题描述】:
更新:我当然尝试添加using System.ComponentModel.DataAnnotations。它不起作用。
问题:我无法在 asp.net vnext 类库项目中使用Required 属性。
案例:
1.添加默认设置的asp.net vnext类库项目。
2. 使用字符串属性Name创建类Human。
3. 将Required 属性添加到Name。
4. 得到编译错误:
Error CS0246 The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)
下面是我的project.json:
{
"version": "1.0.0-*",
"dependencies": {
"System.ComponentModel.Annotations": ""
},
"frameworks": {
"aspnet50": {
},
"aspnetcore50": {
"dependencies": {
"System.Runtime": ""
}
}
}
}
我也可以在 asp.net vnext 中使用DataAnnotations,但不能在 vnext 类库中使用。为什么?
【问题讨论】:
-
为什么投反对票?这对我来说似乎是一个合理的问题。
-
@downvoter,请注意发布原因。
标签: c# asp.net asp.net-mvc class-library