dotnet / dotnet/aspnetcore

Issue on accessing RCL Blazor project page from mvc project

Open
#58,936 0 comments 0 reactions 0 assignees View on GitHub
area-mvc untriaged
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.