コード例 #1
0
        private void WriteLabelWithoutFor(ModelExplorer modelExplorer, TextWriter writer, bool writeId = false)
        {
            var idString = writeId ? $"id=\"{DateLabelId + For.Name}\"" : string.Empty;

            writer.Write($"<label {idString}>{_htmlGenerator.Encode(modelExplorer.Metadata.DisplayName)}");

            if (modelExplorer.Metadata.IsRequired)
            {
                writer.Write(RequiredStarSpan);
            }
            writer.WriteLine("</label>");
        }
コード例 #2
0
ファイル: HtmlHelper.cs プロジェクト: lodejard/AllNetCore
 /// <inheritdoc />
 public string Encode(string value)
 {
     return(_htmlGenerator.Encode(value));
 }
コード例 #3
0
        private void WriteDetails(TextWriter writer)
        {
            string text      = string.Empty;
            string className = "detail-text";

            switch (GetOutputType())
            {
            case OutputType.Enum:
                text = ValuePrefix + EnumHelper.GetDescription(For.ModelExplorer.ModelType, (Enum)For.ModelExplorer.Model);
                break;

            case OutputType.Bool:
                text = ValuePrefix + (((bool)For.ModelExplorer.Model) ? "Ja" : "Nej");
                break;

            case OutputType.NullableBool:
                text = ValuePrefix + (For.ModelExplorer.Model != null ? ((bool)For.ModelExplorer.Model) ? "Ja" : "Nej" : "-");
                break;

            case OutputType.Date:
                text = ValuePrefix + (For.ModelExplorer.Model != null ? ((DateTime)For.ModelExplorer.Model).ToSwedishString("yyyy-MM-dd") : "-");
                break;

            case OutputType.DateTimeOffset:
                text = ValuePrefix + ((DateTimeOffset?)For.ModelExplorer.Model)?.ToSwedishString("yyyy-MM-dd HH:mm");
                break;

            case OutputType.TimeRange:
                var timeRange = (TimeRange)For.ModelExplorer.Model;
                text = ValuePrefix + timeRange.StartDate.ToSwedishString("yyyy-MM-dd") + " "
                       + timeRange.StartTime.ToSwedishString("hh\\:mm") + "-"
                       + timeRange.EndTime.ToSwedishString("hh\\:mm");
                break;

            case OutputType.Currency:
                text = ValuePrefix + ((decimal?)For.ModelExplorer.Model)?.ToSwedishString("#,0.00 SEK");
                break;

            case OutputType.MultilineText:
                className += " line-break";
                text       = ValuePrefix + _htmlGenerator.Encode(For.ModelExplorer.Model);
                break;

            case OutputType.TimeSpan:
                var time = ((TimeSpan?)For.ModelExplorer.Model) ?? TimeSpan.Zero;
                text = ValuePrefix + (time.Hours > 0 ? $"{time.Hours} timmar {time.Minutes} minuter" : $"{time.Minutes} minuter");
                break;

            case OutputType.RadioButtonGroup:
                text = ValuePrefix + ((RadioButtonGroup)For.ModelExplorer.Model).SelectedItem.Text;
                break;

            case OutputType.CheckboxGroup:
                className += " line-break";
                text       = ValuePrefix + ((CheckboxGroup)For.ModelExplorer.Model).SelectedItems
                             .Select(item => item.Text)
                             .Aggregate((current, next) => current + "\n" + next);
                break;

            default:
                text = ValuePrefix + _htmlGenerator.Encode(For.ModelExplorer.Model);
                break;
            }
            if (string.IsNullOrEmpty(text))
            {
                className += " no-value-info";
                text       = Empty;
            }

            text += TextAppend;

            writer.WriteLine($"<div class=\"{className}\">{text}</div>");
        }