https://stackoverflow.com/questions/16870413/how-to-call-another-controller-action-from-a-controller-in-mvc

https://stackoverflow.com/questions/23748511/how-to-get-instance-of-dependency-resolver-in-asp-net-web-api

https://stackoverflow.com/a/32098348/3782855

As @mxmissile says in the comments to the accepted answer, you shouldn't new up the controller because it will be missing dependencies set up for IoC and won't have the HttpContext.

Instead, you should get an instance of your controller like this:

var controller = DependencyResolver.Current.GetService<ControllerB>();
controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);

https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/dependency-injection

how to get a controller instance in another controller的更多相关文章

  1. iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(下)

    这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ...

  2. 【原】push过快的错误 (Pushing the same view controller instance more than once is not supported)

    今天在点击按钮push viewController 时,控制台报错: Terminating app due to uncaught exception 'NSInvalidArgumentExce ...

  3. iOS第八课——Navigation Controller和Tab bar Controller

    今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...

  4. MVC Controller 链接到 API Controller 以及反向链接

    MVC Controller 链接到 API Controller 以及反向链接 问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controll ...

  5. 坑:jmeter代理服务器录制脚本出现target controller is configured to "use recording Controller" but no such controller exists...

    配置好代理服务器后,运行代理服务器 run 报错: target controller is configured to "use recording Controller" bu ...

  6. iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(上)

    这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ...

  7. Jmeter(十八)Logic Controllers 之 Random Controller and Random order Controller

    Random Controller就比较简单了,完全随机!毫无章法. 毫无任何规律的运行. 还有一个Random order Controller,随机顺序控制器就像一个简单的控制器,它将最多执行一次 ...

  8. [水煮 ASP.NET Web API2 方法论](1-4)从 MVC Controller 链接到 API Controller 以及反向链接

    问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controller 的直接链接,或者反向链接. 解决方案 可以使用 System.Web.Htt ...

  9. I2C controller core之Bit controller(03)

    FPGA proven, AISC proven, I2C controller core from OpenCores http://opencores.org/project,i2c Bit-co ...

随机推荐

  1. python之range和xrange

    range 前面小节已经说明了,range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列. 比如: 1 >>> ...

  2. Python 基础之列表去重的几种玩法

    列表去重 1.方法1 借助一个临时列表 ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] for id in ids: if id not in news_ids ...

  3. 《JAVA多线程编程核心技术》 笔记:第七章:拾遗增补

    一.线程的状态 1.1 状态种类及理解:(一共6个) 文字说明和理解: NEW状态:线程实例化后还从未执行start()方法时的状态: RUNNABLE状态:线程进入运行的状态: TERMINATED ...

  4. Making training mini-batches

    Here is where we'll make our mini-batches for training. Remember that we want our batches to be mult ...

  5. python系列十七:Python3 标准库概览

    #!/usr/bin/python #-*-coding:gbk-*- #Python3 标准库概览'''操作系统接口os模块提供了不少与操作系统相关联的函数.建议使用 "import os ...

  6. Maven 整合SSH框架之pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  7. 转!!DNS域名解析使用的是TCP协议还是UDP协议?

    原文地址:https://segmentfault.com/a/1190000006100959 DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP ...

  8. 文件下载(StreamingHttpResponse流式输出)

    文件下载(StreamingHttpResponse流式输出) HttpResponse会直接使用迭代器对象,将迭代器对象的内容存储成字符串,然后返回给客户端,同时释放内存.可以当文件变大看出这是一个 ...

  9. python进程间数据不共享(示例演示)

    import multiprocessing data_list = [] def task(arg): data_list.append(arg) print(data_list) def run( ...

  10. 可采用两种方法得到一个EJB对象

    (本文是转载其他人的技术文章,觉得说得挺浅显易懂,特借来学习)     在前面学习的例子中,只有一个EJB,但是对于一个真实的项目,EJB的数量可以有很多,而且EJB之间也会互相调用,那么在一个EJB ...