示例#1
0
        /// <summary>
        /// Render the start of a basic flow form field with specified HTML for the label and element placeholders.
        /// </summary>
        /// <remarks>
        /// Will render the end of the field after Dispose() is called.<br />
        /// Usually, you would use this within a using block and then use the returned section to output nested fields, e.g.:<br />
        /// using (var ss = s.BeginField("MyLabel", new HtmlString("MyElement")) {<br />
        ///     &#160; &#160; @ss.Field(...)<br />
        /// }
        /// </remarks>
        /// <param name="expression">m => m.BooleanPropertyFromPageModel</param>
        /// <param name="label">The label to add after the checkbox element</param>
        /// <param name="fieldConfiguration">Configuration data for the field</param>
        /// <param name="sectionId">Adds an id to the &lt;dl&gt; of the nested section</param>
        /// <returns>A FlowFormSection object that will be nested within this field and can be used to create nested fields</returns>
        public FlowFormSection <TModel> BeginFieldFor(Expression <Func <TModel, bool> > expression, string label, FieldConfiguration fieldConfiguration = null, string sectionId = null)
        {
            fieldConfiguration = fieldConfiguration ?? new FieldConfiguration();

            var elementHtml = _htmlHelper.CheckBoxFor(expression, fieldConfiguration.HtmlAttributes).ToHtmlString() +
                              _htmlHelper.LabelFor(expression, label);

            string errorHtml;
            var    isValid = GetErrors(expression, out errorHtml);

            var field = new FlowFormField(_writer, true, LabelHtml(expression, fieldConfiguration), elementHtml, errorHtml, isValid, fieldConfiguration.Hint, fieldConfiguration.Tip, fieldConfiguration.HideTip, fieldConfiguration.HintClass, fieldConfiguration.ParentClass, fieldConfiguration.DisplayFieldName);

            return(new FlowFormSection <TModel>(_htmlHelper, true, null, sectionId, parentField: field));
        }
示例#2
0
        public FlowFormSection(HtmlHelper <TModel> htmlHelper, bool nested, string heading, string id = null, IHtmlString hint = null, string hintClass = null, bool optional = false, IHtmlString instructions = null, bool omitDl = false, FlowFormField parentField = null)
        {
            // Starts a section in a flow form
            // The instance variables allow the form to maintain state for child sections and fields
            //     and to allow the writer to accumulate the output for the section
            _htmlHelper  = htmlHelper;
            _nested      = nested;
            _omitDl      = omitDl;
            _parentField = parentField;
            _writer      = htmlHelper.ViewContext.Writer;

            // Generate the html for the beginning of the section from the class compiled from the Razor template
            var generatedSection = HelperDefinitions.BeginSection(nested, heading, id, hint, hintClass, optional, instructions, omitDl, HasParent);

            _writer.Write(generatedSection.ToHtmlString());
        }