ASP.NET MVC Routing: good style to use QueryStrings?

Should all routes in ASP.net MVC follow the philosophy of "Only slashes, without QueryString"?

I am working on 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 the Action? Sort of

 /{pageTitle}?noredirect=true 

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

 /{pageTitle}/NoRedirect 

instead

I think it is clean, but then again I never wrote a complicated MVC application that I had to pass parameters to before :)

+4
source share
1 answer

I believe that there is no definite answer to this question.

But it’s more natural for me to have only controls and actions on the left side of the URL and to have “optional” parameters in the QueryString.

It’s clear that

  • /{pageTitle} will show the article,
  • /{pageTitle}/Edit edit the art,
  • /{pageTitle}/History will show the history of this art

/{pageTitle}/NoRedirect doesn't actually ring. But a little more obvious that /{pageTitle}?noredirect=true changes the behavior of the action.

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

+9
source

Source: https://habr.com/ru/post/1301566/


All Articles