Issue on accessing RCL Blazor project page from mvc project
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
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"
Home
Hello, world!
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
Contributor guide
Assessment
This issue has not been assessed yet.