简体   繁体   中英

Where can I find IController for MVC 6?

        protected virtual IActionResult InvokeHttp404()
    {
        IController errorController = EngineContext.Current.Resolve<CommonController>();
        var routeData = new RouteData();
        routeData.Values.Add("controller", "Common");
        routeData.Values.Add("action", "PageNotFound");
        errorController.Execute(new RequestContext(HttpContext, routeData));
        return new EmptyResult();
    }

In the new Microsoft.AspNet.Mvc, IController could not be found and Execute is not part of IController.

There isn't one - Controller inherits from ControllerBase .

In your scenario, you would need to resolve a reference to a type of CommonController rather than IController , with which you can call your action method directly. Something like;

CommonController errorController = EngineContext.Current.Resolve<CommonController>();
errorController.PageNotFound();
return new EmptyResult();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM