ControllerContext为null [英] ControllerContext is null
问题描述
我有这个MVC4控制器( ControllerB
)
I have this MVC4 controller (ControllerB
):
public class MyControllerB : Controller
{
public bool Check(string actionName, ControllerBase controllerBase)
{
ControllerContext controllerContext = new ControllerContext(this.ControllerContext.RequestContext, controllerBase);
...
}
}
我打电话ControllerB的检查从ControllerA的方法,像这样:
I'm calling ControllerB's Check method from "ControllerA", like so:
bool b = new MyControllerB().Check("Index", this);
我得到对象引用不设置到对象的实例
,因为 this.ControllerContext
为null。
如果我移动检查方法ControllerA,它工作得很好。但我需要这个方法是在不同的控制器。我怎样才能解决我的code,这样``this.ControllerContext`不会以空?
If I move the Check method to ControllerA, it works just fine. But I need this method to be in a different controller. How can I fix my code so that ``this.ControllerContext` will not be null?
推荐答案
在这里找到了答案: HTTP ://forums.asp.net/t/1409129.aspx
不知道这是否是最有效的方法......我不知道在这一点上的另一种方式。
任何想法?
Found the answer here: http://forums.asp.net/t/1409129.aspx Don't know if this is the most efficient way... and I don't know of another way at this point. Any ideas?
这篇关于ControllerContext为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!