From 54f53af9817d32fae4a1a1e6443f348099d7f854 Mon Sep 17 00:00:00 2001 From: Dave Reed Date: Fri, 15 Oct 2010 14:29:56 -0700 Subject: [PATCH] Added Html.LabelFor overloads that accept string and LocalizedString. e.g. Html.LabelFor(m=>m.Tags, T("Tags")) Existing uses NOT converted. Conversion can be accomplished with a VS Regular Expression search/replace: Replace this: \.LabelFor:b*\({[a-zA-Z]+}:b*\=\>:b*\1\.{[a-zA-Z]+}:b*\) With this: .LabelFor(\1=>\1.\2, T("\2")) --HG-- branch : dev --- src/Orchard/Mvc/Html/HtmlHelperExtensions.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs b/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs index d4bf700da..3cb858bed 100644 --- a/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs +++ b/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs @@ -36,6 +36,21 @@ namespace Orchard.Mvc.Html { return id.Replace('[', '_').Replace(']', '_'); } + public static IHtmlString LabelFor(this HtmlHelper html, Expression> expression, LocalizedString labelText) { + return LabelFor(html, expression, labelText.ToString()); + } + + public static IHtmlString LabelFor(this HtmlHelper html, Expression> expression, string labelText) { + if (String.IsNullOrEmpty(labelText)) { + return MvcHtmlString.Empty; + } + var htmlFieldName = ExpressionHelper.GetExpressionText(expression); + var tag = new TagBuilder("label"); + tag.Attributes.Add("for", html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName)); + tag.SetInnerText(labelText); + return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal)); + } + public static MvcHtmlString SelectOption(this HtmlHelper html, T currentValue, T optionValue, string text) { return SelectOption(html, optionValue, object.Equals(optionValue, currentValue), text); }