This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
namespace Kreta.Web.Helpers
{
public static class DisplayTextExtensions
{
public static MvcHtmlString KretaDisplayTextFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, IDictionary<string, object> htmlAttributes = null, string id = null)
{
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
string htmlFieldName = ExpressionHelper.GetExpressionText(expression);
string fullHtmlFieldId = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName);
string text = metadata.Model?.ToString();
if (string.IsNullOrWhiteSpace(text))
{
return MvcHtmlString.Empty;
}
var tag = new TagBuilder("label");
tag.MergeAttributes(htmlAttributes);
if (!string.IsNullOrWhiteSpace(id))
{
tag.MergeAttribute("id", id);
}
tag.MergeAttribute("displayfor", fullHtmlFieldId);
tag.AddCssClass("windowInputValue");
tag.SetInnerText(text);
return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
}
}
}