passing {param} inside page name? is it possible?

Robdob 1 Reputation point
2021-05-04T19:48:52.327+00:00

Hi,

I have an older website where I'm doing a lot of urlrewrite stuff to my old .aspx files and I'm trying to rewrite it using server side blazor

is it possible to pass parameters as part of a url page name?

i.e.

@Anonymous "/information-on-{param}" in my razor pages

or

@Anonymous "/information-on-{param}.html" in my razor pages

or

@Anonymous "/{param}-information.html" in my razor pages

or

@Anonymous "/{param}-information" in my razor pages

when I do this I get a message as such?

InvalidOperationException: Invalid template 'information-on-{param}'. Missing '{' in parameter segment 'information-on-{param}'.

thanks in advance

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,479 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yiyi You - MSFT 521 Reputation points
    2021-05-05T03:03:13.227+00:00

    Hi Robdob-4164,

    here is an official doc of blazor routing.And in the doc,we can see it uses route parameters use a format like @page "/xxx/{param}".

    And here is a demo to use route parameters:
    razor:

    @page "/information-on/{param}"  
    <p>param: @param</p>  
    @code {  
        [Parameter]  
        public string param { get; set; }  
    }  
    

    result:
    93766-5-5-1.png

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    YiyiYou