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>
CodePudding user response:
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.
CodePudding user response:
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.
CodePudding user response:
- Find and open the file [YourProject]->Models->ErrorViewModel.cs
- Copy the namespace name of the ErrorViewModel class.
- Add a new using directive just couple of lines above of the line having the error you reported and paste the copied namespace value.
The newly added using directive will looks like this - using [something].Models
- Now the build should be successful.
CodePudding user response:
If you have changed the file location of ErrorViewModel.cs
- Go to the Views folder then go to the Shared folder and open Error.cshtml
- Add changed location from the ErrorViewModel