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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With