コード例 #1
0
        public static MvcHtmlString DynamicDisplayListFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, string optionLabel, DisplayListType displayType = DisplayListType.SelectedLabel, object viewData = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData, true, true);
            object selectedValue = dynamicComponentBase.FieldValue;
            string selectedText  = selectList.Where(w => w.Value == selectedValue?.ToString()).FirstOrDefault()?.Text;

            switch (displayType)
            {
            case DisplayListType.DropDownList:
                TagBuilder_Select <TModel, TProperty> tagBuilder = new TagBuilder_Select <TModel, TProperty>(dynamicComponentBase);
                tagBuilder.AddOptionLabel(optionLabel);
                tagBuilder.AddOptions(selectList);
                tagBuilder.TagElement.AddInputAttributeStaticValue("disabled", null);
                tagBuilder.TagElement.AddInputAttributeStaticValue("class", "");
                return(tagBuilder.GenerateElementMvcString(TagRenderMode.Normal));

            case DisplayListType.SelectedEdit:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-input" }
                });
                return(TagBuilderGenerators.GenerateTagEditor(dynamicComponentBase.SanitizedId, selectedText, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false, true).ToMvcHtmlString(TagRenderMode.Normal));

            case DisplayListType.OptionsList:
                return(null);

            case DisplayListType.SelectedLabel:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-label" }
                });
                return(TagBuilderGenerators.GenerateTagLabel(dynamicComponentBase.SanitizedId, selectedText, dynamicComponentBase.SanitizedId, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description).ToMvcHtmlString(TagRenderMode.Normal));

            case DisplayListType.SelectedSpan:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-span" }
                });
                return(TagBuilderGenerators.GenerateTagDisplay(dynamicComponentBase.SanitizedId, selectedText, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description).ToMvcHtmlString(TagRenderMode.Normal));

            case DisplayListType.SelectedOnlyText:
            default:
                return(TagBuilderGenerators.GenerateOnlyText(selectedText, dynamicComponentBase.HtmlAttributes));
            }
        }
コード例 #2
0
        public static MvcHtmlString DynamicDisplayFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, Rendering displayType = Rendering.Label, object viewData = null, bool blockShowRequiredSymbol = false, string requiredSymbol = null, string requiredMessage = null, string requiredClass = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData);

            switch (displayType)
            {
            case Rendering.Label:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-label" }
                });
                return(TagBuilderGenerators.GenerateTagLabel(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), null, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false /*!blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired*/, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Span:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-span" }
                });
                return(TagBuilderGenerators.GenerateTagDisplay(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false /*!blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired*/, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Edit:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "form-control control-input" }
                });
                return(TagBuilderGenerators.GenerateTagEditor(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false, true).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Progress:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "form-control control-progress" }
                });
                double?value    = dynamicComponentBase.FieldValue == null ? (double?)null : double.Parse(dynamicComponentBase.FieldValue.ToString());
                double?maxValue = dynamicComponentBase.MetadataAttributes.GetValue <double?>("Progress", "MaxValue");
                return(TagBuilderGenerators.GenerateTagProgress(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, value, maxValue, dynamicComponentBase.FieldModelMetadata.Description, false).ToMvcHtmlString(TagRenderMode.Normal));

            default:
                return(TagBuilderGenerators.GenerateOnlyText(dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, false /*!blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired*/, requiredSymbol, requiredMessage, requiredClass));
            }
        }
コード例 #3
0
        public static MvcHtmlString DynamicDisplayNameFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, Rendering displayType = Rendering.OnlyText, object viewData = null, bool blockShowRequiredSymbol = false, string requiredSymbol = null, string requiredMessage = null, string requiredClass = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData);

            switch (displayType)
            {
            case Rendering.Label:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-label" }
                });
                return(TagBuilderGenerators.GenerateTagLabel($"display_{ dynamicComponentBase.SanitizedId }", dynamicComponentBase.FieldModelMetadata.DisplayName, dynamicComponentBase.SanitizedId, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, !blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Span:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-span" }
                });
                return(TagBuilderGenerators.GenerateTagDisplay($"display_{ dynamicComponentBase.SanitizedId }", dynamicComponentBase.FieldModelMetadata.DisplayName, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, !blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            default:
                return(TagBuilderGenerators.GenerateOnlyText(dynamicComponentBase.FieldModelMetadata.DisplayName, dynamicComponentBase.HtmlAttributes, !blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired, requiredSymbol, requiredMessage, requiredClass));
            }
        }