How to get query params from url in blazor server side app?

Prince
Prince
Member
22 Points
1 Posts

I'm using Blazor Server Side app. Want query parameter value in the blazor page component.

Support url is somthing like:

https://localhost/myblazor?id=45323

Whenever this above url get hit, in the page want id. I have following blazor page:

@namespace MyPortal.Views
@page "/myblazor?id={id}"

<p>Blazor is @id!</p>
@code {
    public string? id { get; set; }
}

But it's not working.

How to get query params from url in blazor server side app?

 

Views: 161
Total Answered: 1
Total Marked As Answer: 1
Posted On: 16-May-2024 03:26

Share:   fb twitter linkedin
Answers
beginer
beginer
Participant
1478 Points
49 Posts
         

hi do following change in your blazor page as:

@namespace MyPortal.Views
@page "/myblazor"

<p>Blazor is @id!</p>
@code {
    [SupplyParameterFromQuery(Name = "id")]
    public string? id { get; set; }
}
Posted On: 18-May-2024 02:53
Thanks. Works for me.
 - Prince  19-May-2024 21:19
 Log In to Chat