public void OnViewComponentExecuting(ViewComponentExecutingContext context)
        {
            if (context.ViewData == null)
            {
                return;
            }

            if (context.ViewData.Model == null)
            {
                return;
            }

            // Does the view components view model implement the ITagHelperAdapterAwareViewModel interface
            if (typeof(ITagHelperAdapterAwareViewModel).IsAssignableFrom(context.ViewData.Model.GetType()))
            {
                // Attempt to safely cast
                var model = context.ViewData.Model as ITagHelperAdapterAwareViewModel;
                if (model != null)
                {
                    // Add adapters to the context before the view component executes
                    context.ViewContext.HttpContext.Items[typeof(TagHelperAdapterCollection)] = model.TagHelperAdapters;
                }
            }
        }
Example #2
0
 public void OnViewComponentExecuting(ViewComponentExecutingContext context)
 {
 }