有没有人为 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/