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);
...
}
}
I'm calling ControllerB's Check method from "ControllerA", like so:
bool b = new MyControllerB().Check("Index", this);
I get Object reference not set to an instance of an object
because this.ControllerContext
is null.
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?