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 🙂
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}/Editwill edit the artice,/{pageTitle}/Historywill show the history of that artice/{pageTitle}/NoRedirectdoesn’t really ring a bell.But it’s a bit more obvious that
/{pageTitle}?noredirect=truemodifies the behaviour of the action.So I would go with
/{pageTitle}?noredirect=truein your case.