init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
35
KretaWeb/Helpers/DisplayTextExtensions.cs
Normal file
35
KretaWeb/Helpers/DisplayTextExtensions.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue