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.
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- How to dynamically load partial view Via jquery aj
- parameters in routing do not work MVC 3
- There is no ViewData item with the key 'taskTy
- TextBoxFor decimal
相关文章
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- Forward request from servlet to jsp
- How to get server path of physical path ?
- Cannot implicitly convert Web.Http.Results.JsonRes
The builtin Django actions suffix _done. So LoginDone would be the page that processes Login (in ASP.NET MVC camel case style).
Rob Conery at MS suggested some useful RESTful style naming for actions.
results in URLs along the lines of (for a forum)
Rob Conery on RESTful Architecture for MVC
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.
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.
Stephen Walther's post on ASP.NET MVC Tip #11 – Use Standard Controller Action Names would probably clarify you regarding to naming convention of
MVC Action
naming convention...Rails has a nice action naming convention for CRUD operations: Rails Routing from the Outside In.
HTTP Verb Path Controller#Action Used for GET /photos photos#index display a list of all photos GET /photos/new photos#new return an HTML form for creating a new photo POST /photos photos#create create a new photo GET /photos/:id photos#show display a specific photo GET /photos/:id/edit photos#edit return an HTML form for editing a photo PATCH/PUT /photos/:id photos#update update a specific photo DELETE /photos/:id photos#destroy delete a specific photo
This is essentially an update to Paul Shannon's answer, since his source (Rob Conery) implicitly says that he copied his list from Rails.