[英]How do I limit the actions in my controller in an ASP.NET MVC application?
I writing an MVC app and I'm really struggling to keep my controllers lean and limit the number of actions. 我写了一个MVC应用程序,我真的在努力使我的控制器保持精简并限制操作数。
For example, here is a look at my ReportController actions: OpenCall 例如,下面是我的ReportController操作:OpenCall
ClosedCall 封闭电话
ServiceLevelAgreement 服务水平协议
Barrier 屏障
Resolution 解析度
Repair 修理
Failure 失败
Inventory 库存
CustomerLocation 客户位置
These are all my different reports. 这些都是我的不同报告。 Should I be making a controller for each one? 我应该为每个控制器做一个控制器吗?
Here is a look at my ServiceCallController actions: New 看一下我的ServiceCallController动作:新建
Create 创造
Reopen 重新开启
UpdateETA 更新ETA
UpdateOnsite 更新现场
UpdateServiceTimes UpdateServiceTimes
UpdateEnroute 更新路线
Close 关
Cancel 取消
Reassign 重新分配
Show 节目
ModifyAfterClose 修改后关闭
This are all different actions I need to take based on what the user wants to do. 这是我根据用户想要执行的所有操作。 Can anyone help me out here with how to clean this up? 谁能帮我解决这个问题?
I think it's clean already. 我认为已经干净了。 If an object of yours is capable of doing 7-8 actions, then your structure is the way to go. 如果您的一个对象能够执行7到8个动作,那么您的结构就是正确的选择。 If you had one controller that is responsible for the actions of multiple business objects, then I'd have suggested you change it into the way your current design is in. 如果您有一个负责多个业务对象动作的控制器,那么我建议您将其更改为当前设计的方式。
One thing though about your current design, it'd be a good idea to just have one update action on ServiceCallController and that action could take what to update as a parameter. 尽管有关当前设计的一件事,对ServiceCallController进行一个更新操作是一个好主意,并且该操作可以将要更新的内容作为参数。 After all, all those update actions do one thing : update your business object. 毕竟,所有这些更新操作都会做一件事:更新业务对象。
But if you are still not satisfied, then you can just have one action that's named "do" which takes the action as parameter and passes that to a service layer which returns what the request wanted. 但是,如果您仍然不满意,则可以只执行一个名为“ do”的操作,该操作将操作作为参数并将其传递给服务层,该服务层将返回请求的要求。 But IMO, that wouldn't be a good design, so I definitely don't suggest it. 但是IMO,那不是一个好的设计,所以我绝对不建议这样做。
如果要使用的文件太大,则可以使用部分类,也可以将逻辑退回到一个单独的类,然后让控制器进行思考和倾斜。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.