![](/img/trans.png)
[英]error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?)
[英]CS0246 The type or namespace name 'ErrorViewModel' could not be found (are you missing a using directive or an assembly reference?)
我收到一個 CS0246 錯誤代碼。 我正在做一個 MVC .net 核心項目。 我將 Razor 合並到我的 C# 代碼中。 我在進行構建時收到此錯誤。 我在最后一行收到錯誤。 誰能幫我解決這個問題?
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"d6a5625cc8fb4476f348b0fe9041c550465d8bf9", @"/Views/Shared/Error.cshtml")]
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"53c99bf587b2b24ba6d4f1516a026a5e81271c09", @"/Views/_ViewImports.cshtml")]
public class Views_Shared_Error : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<ErrorViewModel>
在 Error.cshtml 頁面中,在頁面頂部添加 @model libraryname.ErrorViewModel 而不僅僅是 ErrorViewModel。 然后重建項目,看看它是否有效。
此錯誤通常發生在您編輯文件位置並且無法定向文件時。在我的情況下,_LoginPartial.cshtml 位於共享文件夾之外。如果文件移動到錯誤的文件夾通常會發生這種情況,因此 model 無法指定方向。
新添加的 using 指令將如下所示 - using [something].Models
如果您更改了 ErrorViewModel.cs 的文件位置
出現此問題的原因是ViewModel
class 存儲在根目錄中創建的目錄中。 在這種情況下,新創建的ViewModel
class 的命名namespace
被命名為<root-namespace>.<folder-name>
。 為避免這種情況,使用以下將導致錯誤:
@model <folder-name>.<view-model-name>
避免這種情況的方法是輸入完整的namespace
:
@model <full-namespace>.<view-model-name>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.