views:

81

answers:

1

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 :)

+8  A: 

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.

çağdaş