mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
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:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user