简体   繁体   English

如何限制ASP.NET MVC应用程序中控制器中的动作?

[英]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.

相关问题 ASP.NET MVC-如何将参数传递给其他控制器上的操作 - ASP.NET MVC - how to pass parameters to actions on a different controller 如何在ASP.NET MVC中允许/ Controller / Id? - How do I allow /Controller/Id in ASP.NET MVC? 如何将 ID 传递给 ASP.NET MVC 中的控制器? - How do I pass an ID to the controller in ASP.NET MVC? 如何在C#中使用ASP.NET MVC中的控制器解决集合错误? - How do I resolve collection error with my controller in ASP.NET MVC in C#? 如何在ASP.NET MVC 5项目中获得“添加控制器”和“添加视图”菜单选项? - How do I get the “Add Controller” and “Add View” menu options in my ASP.NET MVC 5 project? 我如何告诉 MVC 中间件我的 class 是 ASP.NET Core 中的一个 Controller? - How do I tell the MVC middleware that my class is a Controller in ASP.NET Core? ASP.NET MVC应用程序中的异步操作 - Async actions in asp.net mvc application 如何找出我的ASP.Net MVC应用程序运行的用户? - How do I find out what user my ASP.Net MVC application is running as? 如何使ASP.NET MVC应用程序使用我的成员资格表? - How do I make an ASP.NET MVC application use my Membership tables? 如何在本地服务器上运行已经存在的asp.net mvc应用程序 - How do I run an already existing asp.net mvc application om my local server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM