model-view-controller - 从另一个 Controller 调用操作方法的最佳方法是什么?

标签 model-view-controller controller invoke actionmethod

从 Controller B 中的 Action-method 方法调用 Controller A 中的 Action-method 方法的最佳方式是什么? 真的有这样的召唤吗?

最佳答案

最好的方法是调用return RedirectToAction()

但正确的方法是将相关代码从 Controller /操作移动到外部位置、服务或业务逻辑层。它们驻留在您的 Controller 中是错误的,它不是这个地方,现在让您头痛如何跳转到另一个 Controller 然后再返回。这是错误的。无需寻找解决方法,只需修复您的架构即可。

关于model-view-controller - 从另一个 Controller 调用操作方法的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9868427/

相关文章:

asp.net-mvc - 无法检索 'MyService.Entities.Email' 的元数据。 'System.Data.Entity.Internal.AppConfig' 的类型初始值设定项引发异常

java - Spring MVC Controller 的误解

reflection - 如何通过反射访问字段的值(Scala 2.8)

node.js - KeyStone JS 帐户 Controller

asp.net-mvc - 使用 IIS 的 MVC "Access is Denied"

c# - 在 ASP.NET MVC 中发送项目集合

c++ - QTreeView、QTableView,显示不同层级的项目

ruby-on-rails - 可以在 rails 中同时使用嵌套和浅层资源吗?如何编写 Controller / View ?

visual-studio - Visual Studio 2019(本身): Exception Has Been Thrown By The Target of an Invocation

javascript - 无法从 html 按钮调用 js 函数