Handling Singular and Plural Controllers/Routes

Just because the default controllers of asp-mvc have singular names, it doesn’t mean you should implement singular form for all your controllers.

The correct answer is: it depends on the default quantity of the resource that your controller represents.

Singular, example the AccountController is singular because it represents actions (action method) pertaining to a single account only.

Plural If your controller contains at least one action method that handles multiple resources in a single request.

Example plural format

users/update/3

The route above makes you think you are editing all users, which does not makes sense if you read it like a sentence. However, if you read your route like query, it will make much more sense.

If we think about it, a route IS a query: {resource}/{action}/{parameter} looks like a query to me.

users/ shorthand of users/all reads “select all users table”

users/123 reads “select single entity from users table”

users/update/123 reads “update single entity from users table”

Major sites use plural format, see sample below

stackoverflow.com/questions          <- list of questions   (multiple)
stackoverflow.com/questions/18570158 <- individual question (single)
stackoverflow.com/questions/ask      <- new question        (single)

stackoverflow.com/users        <- display list of users (multple)
stackoverflow.com/users/114403 <- individual user       (single)

asp.net/mvc/tutorials        <- display list of tutorials (multiple) 
asp.net/mvc/tutorials/mvc-5  <- individual tutorial       (single)

facebook.com/messages/     <- Display list of messages (multiple)
facebook.com/messages/new  <- Create a single message  (single)
facebook.com/messages/john <- view individual messages (multiple)

I believe that English grammar should be strictly incorporated in every programming aspect. It reads more natural and leads to good code hygiene.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)