4

Should all routes in ASP.net MVC follow a "Only slashes, no QueryString" philosophy?

I'm working on a Wiki software, so I have routes like

/{pageTitle}
/{pageTitle/Edit
/{pageTitle/History

etc. for all actions, but what if I want to control the behavior of an Action? Is something like

/{pageTitle}?noredirect=true

okay or considered bad practice? If the latter, is there a better option? Should I create a separate route

/{pageTitle}/NoRedirect

instead?

I think it's clean, but then again I've never written a complicated MVC application that would need passing options to the action before :)

1 Answer 1

9

I believe there's no definite answer to this.

But to me, it feels more natural to just have controller & action related parts in the left part of the URL and have the "optional" parameters in the QueryString.

While it's clear that ;

  • /{pageTitle} will show the article ,
  • /{pageTitle}/Edit will edit the artice,
  • /{pageTitle}/History will show the history of that artice

/{pageTitle}/NoRedirect doesn't really ring a bell.
But it's a bit more obvious that /{pageTitle}?noredirect=true modifies the behaviour of the action.

So I would go with /{pageTitle}?noredirect=true in your case.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.