/// <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); } }
/// <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); }
/// <summary> /// Invokes a parameterless 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> protected void InvokeViewComponent( string componentName, ViewComponentSectionRendereDelegate bodyHandler, IEnumerable <KeyValuePair <string, ViewComponentSectionRendereDelegate> > sectionHandlers) { InvokeViewComponent(componentName, new ParametersDictionary(), bodyHandler, sectionHandlers); }
/// <summary> /// Initializes a new instance of the <see cref="ViewComponentContext"/> class. /// </summary> /// <param name="callingView">The calling view.</param> /// <param name="body">The body.</param> /// <param name="name">The name.</param> /// <param name="parameters">The parameters.</param> public ViewComponentContext(IViewBaseInternal callingView, ViewComponentSectionRendereDelegate body, string name, IDictionary parameters) { this.callingView = callingView; this.body = body; componentName = name; componentParameters = parameters; }
public void RegisterSection(string name, ViewComponentSectionRendereDelegate section) { if (sections == null) { sections = new Hashtable(); } sections[name] = section; }
/// <summary> /// Initializes a new instance of the <see cref="ViewComponentContext"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="body">The body.</param> /// <param name="name">The name.</param> /// <param name="writer">The text writer.</param> /// <param name="parameters">The parameters.</param> public ViewComponentContext(AspViewBase parent, ViewComponentSectionRendereDelegate body, string name, TextWriter writer, IDictionary parameters) { this.parent = parent; this.body = body; componentName = name; default_writer = writer; componentParameters = parameters; }
public void RenderSection(string sectionName) { if (!HasSection(sectionName)) { return; //matching the Brail and NVelocity behavior, but maybe should throw? } ViewComponentSectionRendereDelegate section = (ViewComponentSectionRendereDelegate)sections[sectionName]; section.Invoke(); }
/// <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); }
public void RegisterSection(string name, ViewComponentSectionRendereDelegate section) { if (sections == null) sections = new Hashtable(); sections[name] = section; }
/// <summary> /// Initializes a new instance of the <see cref="ViewComponentContext"/> class. /// </summary> /// <param name="callingView">The parent.</param> /// <param name="body">The body.</param> /// <param name="name">The name.</param> /// <param name="arguments">The arguments.</param> public ViewComponentContext(IViewBaseInternal callingView, ViewComponentSectionRendereDelegate body, string name, params object[] arguments) : this(callingView, body, name, Utilities.ConvertArgumentsToParameters(arguments)) { }
/// <summary> /// Initializes a new instance of the <see cref="ViewComponentContext"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="body">The body.</param> /// <param name="name">The name.</param> /// <param name="writer">The text writer.</param> /// <param name="arguments">The arguments.</param> public ViewComponentContext(AspViewBase parent, ViewComponentSectionRendereDelegate body, string name, TextWriter writer, params object[] arguments) : this(parent, body, name, writer, (IDictionary)Utilities.ConvertArgumentsToParameters(arguments)) { }
/// <summary> /// Invokes a parameterless 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> protected void InvokeViewComponent( string componentName, ViewComponentSectionRendereDelegate bodyHandler, IEnumerable<KeyValuePair<string, ViewComponentSectionRendereDelegate>> sectionHandlers) { InvokeViewComponent(componentName, new ParametersDictionary(), bodyHandler, sectionHandlers); }