2017-03-13 59 views
1

如何访问Asp.Net Core中的ParentActionViewContext,我使用了以下命令,但在核心中它们不可用。 ControllerContext.ParentActionViewContext.RouteData.Values["controller"].ToString();,ControllerContext.ParentActionViewContext.ViewBag.Model as MyViewModelasp.net核心中的ControllerContext.ParentActionViewContext

由于.Net Core上的信息稀少,我无法找到任何关于这些的信息。

在此先感谢。

回答

0
  • 要获取路线数据,你需要使用的ControllerContext.ActionDescriptor代替ControllerContext.ParentActionViewContext现在:

    ControllerContext.ParentActionViewContext.RouteValues.Values; 
    
  • 对于越来越Model。 Controller类都有自己的属性:

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

    所以您可以使用

    var myModel = this.ViewData.Model as MyViewModel; 
    
0

你找不到ParentActionViewContext,因为有在ASP.Net核心没有儿童的行动。它们已被View Components取代。

您只需调用它们,并通过你想要的任何数据,而无需通过请求管道会试(即无模型绑定,过滤器或独立的HTTP上下文)

  • 没有为主题一个很好的介绍性文章here