Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Controller Naming Pluralization

RESTful conventions indicate using plural nouns over singular objects.

What is the pluralization convention for naming ASP.NET MVC controllers, i.e.
ProductController or ProductsController?

like image 903
Petrus Theron Avatar asked Sep 17 '12 13:09

Petrus Theron


People also ask

Should controller name singular or plural?

So the naming should be plural and came case. e.g: :rails generate controller Dogs new index create delete destroy edit" ??

Should controllers be plural rails?

Controller names are either singular or plural : Using “rails g resource” names the controllers plural, which makes sense because I think about them controlling many routes. Resource names are singular : They create a lot of mvc framework, the name you pass will become the model name, and let rails pluralize the rest.

What is controller name in MVC?

In ASP.NET MVC, every controller class name must end with a word "Controller". For example, the home page controller name must be HomeController , and for the student page, it must be the StudentController . Also, every controller class must be located in the Controller folder of the MVC folder structure.


2 Answers

I'm going to have to disagree with the previous answers of using either plural or singular and being consistent. Each controller should use a different convention based on whether they interact with single or multiple entities. Especially since the controller name is used by default in the URL.

While the project templates use singular (HomeController, AccountController), there is only one Home and the Account actions only operate on the single account for the session. I would not expect the URLs of /homes to access the homepage, nor would I expect to go to /accounts to manage my account settings.

The plural HomesController would work for a real estate website that had methods related to listing and searching multiple homes: /homes/new-listings.

like image 189
LouD Avatar answered Sep 18 '22 14:09

LouD


Some MVC Frameworks use plurals, however the MVC project templates contains a controller called AccountController thus suggesting singlular naming.

It doesn't matter. As with most things in the Asp.net MVC framework the choice is yours. There is no real conventions.

It's my personal opinion but what matters is that you pick a scheme and be consistent!

like image 25
Cybermaxs Avatar answered Sep 17 '22 14:09

Cybermaxs