Skip to content

Route parameters with non-string values fails #48866

Closed
@Markz878

Description

@Markz878

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In .NET 8 preview 5, when creating a SSR Blazor app and using route parameters with e.g. int type, the page fails to load with an error: InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Int32'.

Here is the component I used to test this:

@page "/counter/{currentCount:int?}"
<p role="status">Current count: @CurrentCount</p>
@code {
    [Parameter] public int CurrentCount { get; set; }
}

I tried this on .NET 7 Blazor WASM app and it worked.

Expected Behavior

When going to an url https://localhost:7208/counter/5 the CurrentCount property should be set to 5.

Steps To Reproduce

Create a .NET 8 Blazor SSR app, copy the code to a Counter.razor component and navigate to it's url.

.NET Version

8.0.100-preview.5.23303.2

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-routing

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions