Пример #1
0
        /// <summary>
        /// Renders the section with the specified name.
        /// </summary>
        /// <param name="name">The name of the section.</param>
        /// <param name="isRequired">Flag to specify whether the section is required.</param>
        /// <returns>The template writer helper.</returns>
        public virtual TemplateWriter RenderSection(string name, bool isRequired = true)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("The name of the section to render must be specified.");
            }

            var action = _context.GetSectionDelegate(name);

            if (action == null && isRequired)
            {
                throw new ArgumentException("No section has been defined with name '" + name + "'");
            }

            if (action == null)
#if RAZOR4
            { action = (tw) => { } };
#else
            { action = () => { } };
#endif

            return(new TemplateWriter(tw => {
                _context.PopSections(action, tw);
            }));
        }