有人在MVC中建立了良好的行动命名约定吗?我特别关注ASP.net MVC,但这是一个普遍的问题.例如,我有一个显示登录屏幕(Login)的操作和一个处理该页面登录请求的操作(LoginTest).我并不热衷于这些名字,我还有很多应用程序要写.
MS的Rob Conery为动作提出了一些有用的REST风格命名.
* 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"
导致网址(对于论坛)
* 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关于MVC的RESTful架构