SeT*_*ToY 6 c# asp.net asp.net-core-mvc asp.net-core-1.0
我目前正在尝试ASP.NET Core 1.0 RC2.我已将其创建为.NET Framework项目(而不是.NET Core项目),并Models通过项目引用使用.NET Framework 4.5 添加对库的引用:
"frameworks": {
"net46": {
"dependencies": {
"Project.Core": {
"target": "project"
},
"Project.DataAccess": {
"target": "project"
},
"Project.Encryption": {
"target": "project"
},
"Project.Models": {
"target": "project"
},
"Project.Resources": {
"target": "project"
}
}
}
},
Run Code Online (Sandbox Code Playgroud)
现在,在我的视图中添加模型指令时,会发生以下错误:
@model System.Collections.Generic.List<Project.Models.User>
The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage<System.Collections.Generic.List<Project.Models.User>>
The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<System.Collections.Generic.List<Project.Models.User>> Html { get; private set; }
Run Code Online (Sandbox Code Playgroud)
它还显示在intellisense中:无法解析标签'Project.Models.User'并且无法解析符号'model'
我添加了一个项目引用,添加了一个using语句......仍然会发生此错误.这是为什么?
这是RC2 中存在未解决问题的错误.一个解决方法在对我的作品的问题的讨论是:
services.AddMvc()
.AddRazorOptions(options =>
{
var previous = options.CompilationCallback;
options.CompilationCallback = context =>
{
previous?.Invoke(context);
context.Compilation = context.Compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MyClass).Assembly.Location));
};
});
Run Code Online (Sandbox Code Playgroud)
在您的示例中,您需要执行此操作Project.Models.User.
不确定两个项目是否需要4.6.1和更新2,我只尝试过.
| 归档时间: |
|
| 查看次数: |
10725 次 |
| 最近记录: |