I'm getting errors when trying to add Razor to an ASP.NET Core MVC project

Falanga, Rod, DOH 215 Reputation points
2024-07-29T20:10:22.08+00:00

Early this month I started a new ASP.NET Core application, which I'm writing in .NET 8. I used this because I've got to use Windows Authentication. However, I also want to learn Blazor, so I added that to the project.

Now I'm gettings errors in the RouteView.razor file and the Routes.razor file. Here's the RouteView.razor file:

<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />

The errors it is raising are:

  • RZ9985 Multiple components use the tag 'RouteView' (two of this error)
  • CS1061 'RouteView' does not contain a definition for 'RouteData' and no accessible extension method 'RouteData' accepting a first argument of type 'RouteView' could be found
  • CS0103 The name 'routeData' does not exist in the current context (two of this error)
  • CS1061 'RouteView' does not contain a definition for 'DefaultLayout' and no accessible extension method 'DefaultLayout' accepting a first argument of type 'RouteView' could be found
  • CS0246 The type or namespace name 'MainLayout' could not be found (two of this error)

And here's what's in the Routes.razor file:

<Router AppAssembly="typeof(Program).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="routeData" />
        <FocusOnNavigate RouteData="routeData" Selector="h1" />
    </Found>
</Router>

And the error its raising is:- RZ9985 Multiple components use the tag 'RouteView'

I'm not sure why it is raising these errors. I am still too new to Blazor. Is it because I created the ASP.NET Core project first, then added Blazor?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,614 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,596 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,706 Reputation points
    2024-07-29T21:26:00.59+00:00

    no. its your blazer code. normally, the App.Razor references the Routes.Razor, and Routes references the layout. also check your _imports.razor.

    I'd create a new blazor app from the template, and compare to your project. (also try deleting obj & bin folders, then rebuild).

    note: windows authentication is implemented by IIS, and the user handle is passed to asp.net. the default builder normally included this support.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.