Manos.Mvc.View.RenderSection C# (CSharp) Method

RenderSection() public method

public RenderSection ( string name, bool optional = false ) : string
name string
optional bool
return string
        public string RenderSection(string name, bool optional = false)
        {
            // Recursive search for the inner section
            Action section=FindSection(InnerView, name);
            if (section==null)
            {
                if (optional)
                    return String.Empty;

                throw new InvalidOperationException(string.Format("No section named `{0}`", name));
            }

            // Save the inner view's output, render the section and restore the output
            var save = InnerView.Output;
            InnerView.Output = Output;
            section();
            InnerView.Output = save;

            // Return empty string to prevent output
            return string.Empty;
        }