views:

252

answers:

4

Has anybody established a good naming convention for action in MVC? I was specifically looking at ASP.net MVC but it is a general question. For instance I have an action which displays the login screen (Login) and one which process the login request from that page (LoginTest). I'm not keen on the names and I have a lot of the applicaiton left to write.

A: 

The builtin Django actions suffix _done. So LoginDone would be the page that processes Login (in ASP.NET MVC camel case style).

Lou Franco
That is okay, but it implies that logging in has been completed when really the done action is processing the login. Perhaps PromptLogin and Login.
stimms
A: 

It's fairly irrelevant which convention you use for the Controller Action naming, as long as it's consistant for you and easily understood by those working on it.

In the case of your login Actions, LoginDone is fine and in the same was ProcessLogin will is easy to understand, so use a convention that you feel comfortable with.

Personally I would probably side with Login and ProcessLogin, as LoginDone is probably slightly misleading in terms of what the Action is doing - this is of course assuming that the Action is reacting to the users' credentials and checking whether they are valid. You could then pass through to another Action called LoginDone once the login is successful, or LoginFailed if it's not.

Jimmeh
+3  A: 

Rob Conery at MS suggested some useful RESTful style naming for actions.

* Index - the main "landing" page. This is also the default endpoint.
* List - a list of whatever "thing" you're showing them - like a list of Products.
* Show - a particular item of whatever "thing" you're showing them (like a Product)
* Edit - an edit page for the "thing"
* New - a create page for the "thing"
* Create - creates a new "thing" (and saves it if you're using a DB)
* Update - updates the "thing"
* Delete - deletes the "thing"

results in URLs along the lines of (for a forum)

* http://mysite/forum/group/list - shows all the groups in my forum
* http://mysite/forum/forums/show/1 - shows all the topics in forum id=1
* http://mysite/forums/topic/show/20 - shows all the posts for topic id=20

Rob Conery on RESTful Architecture for MVC

Paul Shannon
I also see that with the newest MVC you can set which verbs are accepted by an action so you can name an action Edit for both the initial page load and the saving the information.
stimms
Seems that post from Rob Conery predates the ability to gave both the display form and process form methods named the same. I also note the Nerd Dinner sample has Edit, but the Controller template has Update for modifying an entity.
Richard
A: 

I've found a blog post by Stephen Walther useful for finding a consistent naming scheme. His are also derived from a REST-style naming scheme, with some unique exceptions that he explains.

Dave Weaver
Link doesn't seem to work any longer, it goes to a list of MVC articles but none seem relevant to this discussion. Anyone have an updated link?
Seth Petry-Johnson
Here's the updated link: http://stephenwalther.com/blog/archive/2008/06/27/asp-net-mvc-tip-11-use-standard-controller-action-names.aspx
Dave Weaver