NoviceMe
NoviceMe

Reputation: 3256

Naming convention to use for controllers in mvc3

Lets say we have a website called filmstar.com What should be the home controller? Should it be named filmstar? And what should other actions be? If we have filmstar/actors link. Currently when i click on actors link it opens following url: filmstar/Home/Actors.

So what is the best naming convention here? Can anyone please describe in detail?

Upvotes: 0

Views: 379

Answers (3)

Alberto León
Alberto León

Reputation: 2921

The route should be /filmstart/actors and yes, you need a controller FilmStart controller with the methods returning ActionResult Index and Actors

Upvotes: 0

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93434

The default url is shortened. So you can have a HomeController, and the default action of Index will show up as a url of filmstar.com (because the defaults are hidden).

You can apply this same logic to other controllers. So, you could have an ActorsController, with a default Index action, and then this url shows up as filmstar.com/actors, and a FilmsController with a default Index action that would respond to filmstar.com/films

Think of the controller name as defining characteristic of things. And the action as how to deal with it. Thus, you would have filmstar.com/films/edit if you want to edit a film, and filmstar.com/films/create if you want to create a new film. But, since the default index is hidden, it won't show up in normal views.

Upvotes: 1

Dima
Dima

Reputation: 6741

There is no best naming convention, there is only default one "donain//"

Probably you are looking for url optimizations and SEO, in this case you can manage all your urls in global.asax using

RouteTable.Routes.MapRoute("Actors", "actors", new { controller = "Actors", action = "Index" } );

Upvotes: 0

Related Questions