public static void EnumTemplate(HtmlHelper html, IXcstPackage package, ISequenceWriter <object> seqOutput) { XcstWriter output = DocumentWriter.CastElement(package, seqOutput); string? className = GetEditorCssClass(new EditorInfo("Enum", "select"), null); var htmlAttributes = CreateHtmlAttributes(html, className); ViewDataDictionary viewData = html.ViewData; Type modelType = viewData.ModelMetadata.ModelType; Type enumType = Nullable.GetUnderlyingType(modelType) ?? modelType; if (!enumType.IsEnum) { throw new InvalidOperationException("Enum template can only be used on Enum members."); } string?formatString = viewData.ModelMetadata.EditFormatString ?? viewData.ModelMetadata.DisplayFormatString; bool applyFormatInEdit = viewData.ModelMetadata.EditFormatString != null; IList <SelectListItem> options = EnumOptions(enumType, output, formatString, applyFormatInEdit); string optionLabel = viewData.ModelMetadata.Watermark ?? String.Empty; SelectInstructions.SelectHelper(html, output, viewData.ModelMetadata, String.Empty, options, optionLabel, multiple: false, htmlAttributes: htmlAttributes); }
public static void ListBoxTemplate(HtmlHelper html, IXcstPackage package, ISequenceWriter <object> seqOutput) { XcstWriter output = DocumentWriter.CastElement(package, seqOutput); string? className = GetEditorCssClass(new EditorInfo("ListBox", "select"), null); var htmlAttributes = CreateHtmlAttributes(html, className); ViewDataDictionary viewData = html.ViewData; IEnumerable <SelectListItem>?options = Options(viewData); SelectInstructions.SelectHelper(html, output, viewData.ModelMetadata, String.Empty, options, optionLabel: null, multiple: true, htmlAttributes: htmlAttributes); }
public static void DropDownListTemplate(HtmlHelper html, IXcstPackage package, ISequenceWriter <object> seqOutput) { XcstWriter output = DocumentWriter.CastElement(package, seqOutput); string? className = GetEditorCssClass(new EditorInfo("DropDownList", "select"), null); var htmlAttributes = CreateHtmlAttributes(html, className); ViewDataDictionary viewData = html.ViewData; string?optionLabel = null; IEnumerable <SelectListItem>?options = Options(viewData); OptionList?optionList = options as OptionList; if (optionList?.AddBlankOption == true) { optionLabel = viewData.ModelMetadata.Watermark ?? String.Empty; } SelectInstructions.SelectHelper(html, output, viewData.ModelMetadata, String.Empty, options, optionLabel, multiple: false, htmlAttributes: htmlAttributes); }