Castle.MonoRail.Framework.Controller.DirectRender C# (CSharp) Method

DirectRender() public method

Sends raw contents to be rendered directly by the view engine. It's up to the view engine just to apply the layout and nothing else.
public DirectRender ( string contents ) : void
contents string Contents to be rendered.
return void
		public void DirectRender(string contents)
		{
			CancelView();

			if (directRenderInvoked)
			{
				throw new ControllerException("DirectRender should be called only once.");
			}

			directRenderInvoked = true;

			viewEngineManager.ProcessContents(context, this, contents);
		}

Usage Example

		protected void RenderFromTemplate(String templateName, Controller controller)
		{
			StringWriter writer = new StringWriter();

			IDictionary context = new Hashtable();

			context.Add("flash", controller.Context.Flash);

			foreach(DictionaryEntry entry in controller.PropertyBag)
			{
				context.Add(entry.Key, entry.Value);
			}
			
#if USE_LOCAL_TEMPLATES
			templateEngine.Process( context, templateName, writer );
#else
			templateEngine.Process( context, "Castle.MonoRail.ActiveRecordScaffold/Templates/" + templateName, writer );
#endif

			if (useDefaultLayout)
			{
				StringWriter layoutwriter = new StringWriter();
				
				context.Add("childContent", writer.GetStringBuilder().ToString());
				
#if USE_LOCAL_TEMPLATES
				templateEngine.Process(context, "layout.vm", layoutwriter);
#else
				templateEngine.Process(context, "Castle.MonoRail.ActiveRecordScaffold/Templates/layout.vm", layoutwriter);
#endif
				
				writer = layoutwriter;

				controller.CancelView();
				controller.Response.Write(writer.GetStringBuilder().ToString());
			}
			else
			{
				controller.DirectRender(writer.GetStringBuilder().ToString());
			}
		}