I have an existing MVC project and I am trying to integrate Blazor into it. To do this I had to upgrade from .NET Core 2.1 to 3.1 and change a few things in my startup class to get the application working as it was before.
After sorting all the upgrade stuff out, I've now added the hub to my Configure
startup method:
...
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllers();
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
});
... and the server sign Blazor services registration:
...
services
.AddMvc(options =>
{
...
})
.AddRazorOptions(o =>
{
...
})
.AddRazorPagesOptions(options =>
{
...
});
services.AddServerSideBlazor();
Finally, I've added the Blazor JS script to my ~/Pages/Shared/_Layout.cshtml
view:
<script src="~/_framework/blazor.server.js"></script>
I'm struggling to figure out what the @page
value should be for a new Razor Component when the component is within a view.
Here is my folder structure:
Everything inside the Pages
folder is new.
Here is the contents of Index.razor
:
@page "/"
<h3>Sales Homepage</h3>
@code {
}
I've tried the following for the @page
route value:
- "/"
- "/Index"
- "/Pricing/Sales/"
- "/Pricing/Sales/Index"
None of these have worked - I just get a page not found error.
I'm also not sure how I'm supposed to use my existing layout in ~/Pages/Shared/_Layout.cshtml
with these new components.
I've had a look at the scaffolded Blazor template project in Visual Studio and also checked the docs but haven't found this particularly useful as it's all focused on brand new Blazor projects.