Open
Description
Hi everyone,
I am trying to create RCL project with blazor pages and this will be used by another MVC project.
I want to return blazor page from controller of MVC project.
For example. In RCL, I have /Pages/Weather.razor with
@page "/Weather"
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
In Mvc , I have HomeController.cs
public IActionResult Weather()
{
return Redirect("/Weather"); // Redirecting to the Home.razor page in the RCL
}
My Program.cs looks like
;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages()
.AddApplicationPart(Assembly.Load("RazorClassLibrary1")); // Ensure the correct assembly name
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages(); // Ensure Razor Pages are mapped, including from RCL
app.UseAuthorization();
// Route for controller
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
When i go to URl https://localhost:7220/Weather, it show HTTP Error 404 saying no webpage found for web address.
Could you suggest me some ideas about what could went wrong?
Thank you