Created
November 20, 2011 09:55
-
-
Save orhanveli/1380099 to your computer and use it in GitHub Desktop.
ASP.NET MVC custom html helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyCMS.Helpers | |
{ | |
public static class Html | |
{ | |
public static MvcHtmlString DescriptionFor<TModel, TValue>( | |
this HtmlHelper<TModel> self, | |
Expression<Func<TModel, TValue>> expression) | |
{ | |
var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData); | |
var description = Localizer.Translate(metadata.Description); | |
return MvcHtmlString.Create(string.Format(@"<span class=""help-block"">{0}</span>", description)); | |
} | |
public static MvcHtmlString NameFor<TModel, TValue>( | |
this HtmlHelper<TModel> self, | |
Expression<Func<TModel, TValue>> expression) | |
{ | |
var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData); | |
var name = Localizer.Translate(metadata.DisplayName); | |
return MvcHtmlString.Create(string.Format(@"<label for=""{0}"">{1}</label>", metadata.PropertyName, name)); | |
} | |
public static MvcHtmlString LabelFor<TModel, TValue>( | |
this HtmlHelper<TModel> self, | |
Expression<Func<TModel, TValue>> expression, | |
bool showToolTip | |
) | |
{ | |
var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData); | |
var name = Localizer.Translate(metadata.DisplayName); | |
return MvcHtmlString.Create(string.Format(@"<label for=""{0}"">{1}</label>", metadata.PropertyName, name)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment