[英]CS0246 The type or namespace name 'ErrorViewModel' could not be found (are you missing a using directive or an assembly reference?)
I am getting a CS0246 error code.我收到一个 CS0246 错误代码。 I am doing a MVC .net core project.
我正在做一个 MVC .net 核心项目。 I am incorporating Razor in my C# code.
我将 Razor 合并到我的 C# 代码中。 I received this error having doing a build.
我在进行构建时收到此错误。 I am getting an error on the last line.
我在最后一行收到错误。 Could anyone help me figure this out?
谁能帮我解决这个问题?
[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>
In Error.cshtml page add @model libraryname.ErrorViewModel at the top of the page instead of just ErrorViewModel.在 Error.cshtml 页面中,在页面顶部添加 @model libraryname.ErrorViewModel 而不仅仅是 ErrorViewModel。 Then rebuild the project and see if it works.
然后重建项目,看看它是否有效。
this error usually occurs when you edit the file placement and unable to direct the file.In my case _LoginPartial.cshtml was outside the shared folder.It usually occurs if file moved to the wrong folder so the model can't specify the direction.此错误通常发生在您编辑文件位置并且无法定向文件时。在我的情况下,_LoginPartial.cshtml 位于共享文件夹之外。如果文件移动到错误的文件夹通常会发生这种情况,因此 model 无法指定方向。
The newly added using directive will looks like this - using [something].Models新添加的 using 指令将如下所示 - using [something].Models
If you have changed the file location of ErrorViewModel.cs如果您更改了 ErrorViewModel.cs 的文件位置
The reason for this problem is that the ViewModel
class is stored in a directory created in the root directory.出现此问题的原因是
ViewModel
class 存储在根目录中创建的目录中。 In this case, the namespace
of the newly created ViewModel
class is named <root-namespace>.<folder-name>
.在这种情况下,新创建的
ViewModel
class 的命名namespace
被命名为<root-namespace>.<folder-name>
。 To avoid this situation, using the following will result in an error:为避免这种情况,使用以下将导致错误:
@model <folder-name>.<view-model-name>
The way to avoid this is to type the full namespace
:避免这种情况的方法是输入完整的
namespace
:
@model <full-namespace>.<view-model-name>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.