ImC*_*sed 12 c# asp.net visual-studio razor asp.net-core
我正在尝试完成本教程(ASP.Net Core Razor Pages),但是(通常)在构建解决方案时,出现CS0234错误,指出文件'Index.g.cshtml.cd'中缺少命名空间。 ..…。但是该文件在哪里存在?我已经尝试过1.所有的build / clean / rebuild解决方案选项。2.我重新启动了Visual Studio。3.我已删除了调试文件,并重新启动了VS和FINALLY。4.我重新启动了PC。似乎可行的唯一解决方案是删除整个解决方案/项目,然后重新开始。
当然必须对此进行修复吗?你能帮忙吗?
If an error says a using directive or namespace is missing from xxx.g.cshtml.cs
, that usually means, that there is a directive directly in the view (.cshtml
or .vbhtml
), that the compiler cannot resolve.
In my case I had the following statement in a partial view:
@inject UserManager<AppUser> UserManager
Run Code Online (Sandbox Code Playgroud)
I then went along and refactored the AppUser class from the web application Namespace.Web.AppUser
into Namespace.Entities.AppUser
, which then was causing that error.
有多种解决方法。最简单的方法是使用完全限定的类型名称空间:
@inject UserManager<Namespace.Entities.AppUser> UserManager
Run Code Online (Sandbox Code Playgroud)
并且不要忘记添加对另一个项目的引用(如果它在另一个项目中)。或者:添加一条using语句:
@using Namespace.Entities;
Run Code Online (Sandbox Code Playgroud)
或者:将上述using语句添加到中~\Views\_ViewStart.cshtml
。这将使该类在所有视图中可用。
小智 9
我在使用 Visual Studio 2019 16.2.2 时遇到了相同的错误。对我来说,我更改了一些模型的名称,而不是在使用模型的实际视图中发现错误,错误显示在 page.g.cshtml 而不是 page.cshtml 中。
所以,我的解决方案相当简单。如果错误出现在 page.g.cshtml 中,忽略 g,转到查看 page.cshtml,将模型名称更新为正确的名称,重建和错误消失。
你可以尝试下面的解决方案
归档时间: |
|
查看次数: |
3344 次 |
最近记录: |