Example #1
0
        /// <summary>
        /// Invokes a view component, and registeres section handlers
        /// </summary>
        /// <param name="componentName">The view component name</param>
        /// <param name="bodyHandler">Delegate to render the component's body. null if the component does not have a body</param>
        /// <param name="sectionHandlers">Delegates to render the component's sections, by the delegate names</param>
        /// <param name="parameters">The parameters to be passed to the component</param>
        protected void InvokeViewComponent(string componentName, ViewComponentSectionRendereDelegate bodyHandler,
                                           IEnumerable <KeyValuePair <string, ViewComponentSectionRendereDelegate> >
                                           sectionHandlers, params object[] parameters)
        {
            ViewComponentContext viewComponentContext = new ViewComponentContext(
                this, bodyHandler,
                componentName, parameters);

            if (sectionHandlers != null)
            {
                foreach (KeyValuePair <string, ViewComponentSectionRendereDelegate> pair in sectionHandlers)
                {
                    viewComponentContext.RegisterSection(pair.Key, pair.Value);
                }
            }
            ViewComponent viewComponent =
                ((IViewComponentFactory)Context.GetService(typeof(IViewComponentFactory))).Create(componentName);

            viewComponent.Init(Context, viewComponentContext);
            viewComponent.Render();
            if (viewComponentContext.ViewToRender != null)
            {
                OutputSubView("\\" + viewComponentContext.ViewToRender, viewComponentContext.ContextVars);
            }
        }
Example #2
0
        /// <summary>
        /// Invokes a view component, and registeres section handlers
        /// </summary>
        /// <param name="componentName">The view component name</param>
        /// <param name="parameters">The parameters to be passed to the component</param>
        /// <param name="bodyHandler">Delegate to render the component's body. null if the component does not have a body</param>
        /// <param name="sectionHandlers">Delegates to render the component's sections, by the delegate names</param>
        protected void InvokeViewComponent(
            string componentName,
            IDictionary parameters,
            ViewComponentSectionRendereDelegate bodyHandler,
            IEnumerable <KeyValuePair <string, ViewComponentSectionRendereDelegate> > sectionHandlers)
        {
            var viewComponentContext = new ViewComponentContext(
                this, bodyHandler,
                componentName, parameters);

            if (sectionHandlers != null)
            {
                foreach (var pair in sectionHandlers)
                {
                    viewComponentContext.RegisterSection(pair.Key, pair.Value);
                }
            }
            var viewComponentFactory = (IViewComponentFactory)Context.GetService(typeof(IViewComponentFactory));
            var viewComponent        = viewComponentFactory.Create(componentName);

            viewComponent.Init(Context, viewComponentContext);
            viewComponent.Render();
            if (viewComponentContext.ViewToRender != null)
            {
                OutputSubView("\\" + viewComponentContext.ViewToRender);
            }
            viewComponentFactory.Release(viewComponent);
        }
Example #3
0
		/// <summary>
		/// Invokes a view component, and registeres section handlers
		/// </summary>
		/// <param name="componentName">The view component name</param>
		/// <param name="bodyHandler">Delegate to render the component's body. null if the component does not have a body</param>
		/// <param name="sectionHandlers">Delegates to render the component's sections, by the delegate names</param>
		/// <param name="parameters">The parameters to be passed to the component</param>
		protected void InvokeViewComponent(string componentName, ViewComponentSectionRendereDelegate bodyHandler,
		                                   IEnumerable<KeyValuePair<string, ViewComponentSectionRendereDelegate>>
		                                   	sectionHandlers, params object[] parameters)
		{
			ViewComponentContext viewComponentContext = new ViewComponentContext(
				this, bodyHandler,
				componentName, parameters);

			if (sectionHandlers != null)
				foreach (KeyValuePair<string, ViewComponentSectionRendereDelegate> pair in sectionHandlers)
					viewComponentContext.RegisterSection(pair.Key, pair.Value);
			ViewComponent viewComponent =
				((IViewComponentFactory) Context.GetService(typeof (IViewComponentFactory))).Create(componentName);
			viewComponent.Init(Context, viewComponentContext);
			viewComponent.Render();
			if (viewComponentContext.ViewToRender != null)
				OutputSubView("\\" + viewComponentContext.ViewToRender, viewComponentContext.ContextVars);
		}