Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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>
like image 889
Willie Mason Avatar asked Oct 14 '25 04:10

Willie Mason


2 Answers

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.

like image 185
Juandre Avatar answered Oct 16 '25 17:10

Juandre


  1. Find and open the file [YourProject]->Models->ErrorViewModel.cs
  2. Copy the namespace name of the ErrorViewModel class.
  3. 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

  1. Now the build should be successful.
like image 32
Raihan Avatar answered Oct 16 '25 17:10

Raihan