动作命名约定 [英] Action Naming Convention

查看:104
本文介绍了动作命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人确定在MVC一个好的行动命名约定?我是专门寻找ASP.net MVC但它是一个普遍的问题。比如我有一个显示登录界面(登录)和其中一个处理从该页面(LoginTest)登录请求的操作。我并不热衷于的名字和我有很多的应用程序了留下来写。


解决方案

罗布科纳在MS建议采取行动了一些有用的RESTful风格的命名。


  *索引 - 的主要登陆页面。这也是默认的端点。
*清单 - 不管的东西名单你向他们展示 - 同类产品的列表。
*显示 - 任何的东西的特定项目你向他们展示(如产品)
*编辑 - 为东西编辑页面
*新的 - 为东西一个创建页面
*创建 - 创建一个新的东西(并保存它,如果您使用的是DB)
*更新 - 更新了东西
*删除 - 删除东西


结果沿着线(用于论坛)网址


  * HTTP:// mysite的/论坛/组/列表 - 显示所有组我的论坛
* HTTP:// mysite的/论坛/论坛/显示/ 1 - 显示所有的主题论坛中ID = 1
* HTTP:// mysite的/论坛/主题/显示/ 20 - 显示了主题ID = 20的所有帖子


罗布科纳对MVC RESTful架构

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.

解决方案

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

这篇关于动作命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆