0

I would like to create friendly routes that map to different query string values of a single Razor Page and it's base GET handler. I'd be fine with switching the query string to being a part of the route as well. The idea is we have a single page that loads a file list and can filter. I'd prefer it if the URL was more straight forward. If it's not possible I could just go with /Files/In or /Files/Out

Example

/Files?direction=In  -> /In
/Files?direction=Out -> /Out

Is there any way to do something like this?

1 Answer 1

3

You can use route data parameters which are defined in a Route Template as part of the @page directive in the .cshtml file :

@page "{direction?}"

Then you can access the route parameter value in OnGet method of your file page :

public void OnGet(string direction)
{
     if (!string.IsNullOrEmpty(direction))
     {
           //filter files based on direction

     }
}

You can pass direction value as /Files/In or /Files/Out , without filter directly use /Files .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.