I am getting a CS0246 error code. I am doing a MVC .net core project. I am incorporating Razor in my C# code. 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. 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.
The newly added using directive will looks like this - using [something].Models
If you have changed the file location of ErrorViewModel.cs
The reason for this problem is that the ViewModel
class is stored in a directory created in the root directory. In this case, the namespace
of the newly created ViewModel
class is named <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
:
@model <full-namespace>.<view-model-name>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.