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
This commit is contained in:
Dave Reed
2010-10-15 14:29:56 -07:00
parent 02a57cc505
commit 54f53af981

View File

@@ -36,6 +36,21 @@ namespace Orchard.Mvc.Html {
return id.Replace('[', '_').Replace(']', '_');
}
public static IHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, LocalizedString labelText) {
return LabelFor(html, expression, labelText.ToString());
}
public static IHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> 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<T>(this HtmlHelper html, T currentValue, T optionValue, string text) {
return SelectOption(html, optionValue, object.Equals(optionValue, currentValue), text);
}