Querystring in the URL without?

Viewed 27

I am working with asp.net core razor pages. I remember a years ago working with MVC, I was able to redirect to a page with querystring without the question mark, but a slash instead.

http://www.exampletest.com/contact/mike@gmail.com

Now in with razor pages, the URL is back to looking like...

http://www.exampletext.com/contact?ID=mike@gmail.com

Is there a way to once again get the querystring with a slash instead of question mark, like before?

My code is as follows:

            <a asp-page="Index" asp-route-id="mike@gmail.com">
                @Html.DisplayFor(m => stock.Symbol) 
            </a>

The Index.cshtml page is in the "contact" directory.

1 Answers

The "querystring without the question mark" is known as route data, with each item occupying a segment of the URL. Route data parameters are defined in a route template, which you pass to the @page directive in the Razor file itself.

Change the @page directive in the Index.cshtml to the following and it should all magically work:

@page "{id}"
Related