Example #1
0
        private static Tag BuildSelectTag <TModel, TProperty, TDisplayValue>(HtmlHelpers <TModel> htmlHelper, Expression <Func <TModel, TProperty> > property,
                                                                             IEnumerable <KeyValuePair <TProperty, TDisplayValue> > values)
        {
            var currentValue    = htmlHelper.Model.Read(property);
            var inputProperties = InputProperties.Get(property);

            var hasSelected = false;

            //TODO: Use id of feed instead of values
            var options = values.Select(item =>
            {
                bool isSelected = item.Key.Equals(currentValue);
                if (isSelected)
                {
                    hasSelected = true;
                }
                return(Tags.Input.Option().Selected(isSelected).Content(item.Value).Value(item.Key));
            });

            if (!hasSelected)
            {
                //TODO: Instead of hardcoded string use placeholder from display attribute
                var placeholderOption =
                    Tags.Input.Option().Disabled().Selected(true).Content(HttpUtility.HtmlEncode(inputProperties.Placeholder));
                options = new[] { placeholderOption }.Union(options);
            }

            var finalOption = options.ToArray();
            var selectTag   = Tags.Input.Select().Content(finalOption).Name(inputProperties.Path);

            return(selectTag);
        }
Example #2
0
        private static IHtmlString BuildFormControlInput <TModel, TProperty>(HtmlHelpers <TModel> htmlHelper, Expression <Func <TModel, TProperty> > property, Tag input)
        {
            var inputProperties = InputProperties.Get(property);

            TProperty value = htmlHelper.Model.Read(property);

            input.Classes(BootstrapClass.FormControl)
            .Id(inputProperties.Path)
            .Name(inputProperties.Path)
            .Value(value);

            if (!string.IsNullOrWhiteSpace(inputProperties.Placeholder))
            {
                input.Placeholder(inputProperties.Placeholder);
            }

            return(BuildFormControl(inputProperties.Path, inputProperties.Name, input));
        }