Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net MVC Routing: Is it good style to use QueryStrings?

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

like image 867
Michael Stum Avatar asked Jan 22 '23 13:01

Michael Stum


1 Answers

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.

like image 170
Çağdaş Tekin Avatar answered Jan 27 '23 06:01

Çağdaş Tekin