asp.net-mvc - Action 命名约定

标签 asp.net-mvc model-view-controller

有没有人为 MVC 中的 action 建立一个好的命名约定?我特别关注 ASP.net MVC,但这是一个普遍的问题。例如,我有一个显示登录屏幕 (Login) 的操作和一个处理来自该页面的登录请求 (LoginTest)。我不热衷于名字,我还有很多应用程序要写。

最佳答案

MS 的 Rob Conery 建议了一些有用的 RESTful 风格的 Action 命名。

* 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 on RESTful Architecture for MVC

关于asp.net-mvc - Action 命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/118474/

相关文章:

c# - 如何在 IIS8 上部署 ASP.NET MVC 4 网站

c# - 如何将值从 Controller 返回到 View 的标签

django - 在templatetags之间传递上下文,Django

ios - 如果我执行 unwind segue (show),母 View Controller 如何获取 subview Controller ?

c# - 使用 formsauthentication 登录并使用 HttpContext.Current.User.Identity

javascript - 如何将数据发送到 KendoWindow 关闭事件

.net - 使用 T4 模板与 EF4.1 简化 API 模型优先方法从模型生成 POCO 类

javascript - 如何从 MVC asp.net Controller 为 javascript 变量赋值

c# - 无法在运行时转换对象

ruby-on-rails - Rails 中的多页表单