the second link is just for converting a razor page to a Blazor page. to host a Blazor component on a razor page, is more complex:
https://zcusa.951200.xyz/en-us/aspnet/core/blazor/components/integration?view=aspnetcore-9.0
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I've got another Blazor question. I started an ASP.NET Razor application a couple months back, because as I understood it at the time, it was the best way of getting to use Windows Authentication. And I know that it is possible to host Blazor components within Razor pages. So far, it seems to be working.But I would like to take one of my Razor pages, and convert it to a Blazor component. I found a good Microsoft Learn course on this here: https://zcusa.951200.xyz/en-us/aspnet/core/blazor/forms/input-components?view=aspnetcore-8.0
And I had hoped all I'd have to do was rename the .cshtml file to .razor and I'd be done. But before I did that, I searched to see if my simple approach would work. It looks like it is more complicated then I thought. I found this page which describes migrating a Razor page to Blazor https://www.devgem.io/posts/step-by-step-guide-to-migrating-asp-net-core-razor-pages-to-blazor
So, is that second link, correct? Is the steps I need to do in order to convert my Razor page to a Blazor component?
the second link is just for converting a razor page to a Blazor page. to host a Blazor component on a razor page, is more complex:
https://zcusa.951200.xyz/en-us/aspnet/core/blazor/components/integration?view=aspnetcore-9.0
Hi,@Falanga, Rod, DOH
So, is that second link, correct?
The codes in second document to host razor components is not correct
builder.Services.AddSignalR();
builder.Services.AddServerSideBlazor();
.....
app.UseStaticFiles();
app.UseRouting();
app.UseBlazorFrameworkFiles();
app.UseAuthorization();
app.MapRazorPages();
// don't remove if you still have Razor pages
app.MapDefaultControllerRoute();
app.MapBlazorHub();
the services registered are for blazor server apps and the middleware app.UseBlazorFrameworkFiles();
is for blazor webassembly apps
although there exists the route in test component:
@page "/Test"
The test component is not routeble at all.
Based on Bruce's answer, notice the .net version of your app,in .net 7 or lower versions ,you need _host.cshtml for all your razor components to be rendered on ,in .net 8 or higher versions,you could use app.razor instead
document for .net 7 and document for .net 8
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Ruikai Feng