ASP .NET MVC - 控制器数量 [英] ASP .NET MVC - Number of Controllers

查看:153
本文介绍了ASP .NET MVC - 控制器数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否应该为需要在一个系统中被操纵的每个表中的一个单独的控制器?

作为一个例子,在设计一个内容管理系统的管理部分,应该有配置每种查找域如下一个单独的控制器:

  / DataTypeA /列表--​​list对于A
/ DataTypeA /创建 - 创建新的数据



/ DataTypeB /列表--​​list对B

还是应该有只是一个管理控制器内单独的操作如下:

  /管理/ DataTypeA  - 此列出DataTypeA
/行政/ DatatypeB - 此列出DataTypeB
/行政/ DataTypeA_Create - 创建一个新的DataTypeA
/行政/ DataTypeB_Create - 创建一个新的DataTypeB


解决方案

我的做法是创建在系统中的主要参与者(表)一个新的控制器。辅助表结束开始由控制器为辅助数据相关联的主表更新。例如,我将有一个用户控制器,并有行动,更新与在用户控制器,而不是创建一个单独的UserContact控制器特定用户关联的UserContact信息。

Should there be a separate controller for each table that needs to be manipulated in a system?

As an example, in designing an administration section of a content management system, should there be a separate controller for configuring each look up domain as follows:

/DataTypeA/List --list for A
/DataTypeA/Create -- create new data
.
. 
.
/DataTypeB/List --list for B

or should there just be separate actions within an Admin controller as follows

/Admin/DataTypeA -- this lists DataTypeA
/Admin/DatatypeB -- this lists DataTypeB
/Admin/DataTypeA_Create -- Create a new DataTypeA
/Admin/DataTypeB_Create -- Create a new DataTypeB

解决方案

My approach is to create a new controller for the primary actors (tables) in the system. Ancillary tables end up begin updated by the controller for the primary table that the ancillary data is associated with. For example, I would have a User controller and have an action to update the UserContact information that is associated with a particular user in the User controller rather than create a separate UserContact controller.

这篇关于ASP .NET MVC - 控制器数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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