Guest User

Untitled

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2. using System.Linq.Expressions;
  3. using System.Web.Mvc;
  4.  
  5. namespace MvcHtmlHelpers
  6. {
  7. public static class HtmlHelperExtensions
  8. {
  9. /// <summary>
  10. /// Return the raw DisplayName attribute of a property of a Model,
  11. /// a-la @Html.LabelFor, without the label.
  12. /// </summary>
  13. /// <typeparam name="TModel">Model to access</typeparam>
  14. /// <typeparam name="TValue">Property of model to access.</typeparam>
  15. /// <param name="self">Default parameter. Always passed.</param>
  16. /// <param name="expression">Lambda expression to evaluate.</param>
  17. /// <returns>DisplayName as a raw String with no markup.</returns>
  18. public static MvcHtmlString DisplayNameFor<TModel, TValue>(
  19. this HtmlHelper<TModel> self,
  20. Expression<Func<TModel, TValue>> expression
  21. )
  22. {
  23. var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData);
  24.  
  25. return new MvcHtmlString(metadata.DataTypeName);
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment