Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ControllerContext.ParentActionViewContext in asp.net core

How can I access ParentActionViewContext in Asp.Net Core, I used following commands, but in core they are not available. ControllerContext.ParentActionViewContext.RouteData.Values["controller"].ToString();, ControllerContext.ParentActionViewContext.ViewBag.Model as MyViewModel

I was not able to find anything regarding these due to scarcity of information on .Net Core.

Thanks in advance.

like image 890
sneuly Avatar asked Jul 27 '26 07:07

sneuly


1 Answers

  • To get route data, you need to use ControllerContext.ActionDescriptor instead of ControllerContext.ParentActionViewContext now:

    ControllerContext.ParentActionViewContext.RouteValues.Values;
    
  • Regarding getting Model. Controller class has own properties:

    public dynamic ViewBag { get; }
    public ViewDataDictionary ViewData { get; set; }
    

    so you may use

    var myModel = this.ViewData.Model as MyViewModel;
    
like image 199
Set Avatar answered Jul 29 '26 21:07

Set