I am wondering if anyone tried to write an extension helper for LabelExtensions.LabelFor HtmlHelper in MVC2? This would be useful for me in that my application requires me to always write tags in a <td> tag with a class attribute. Instead of repeating this code in a view, I thought I could write a small extension method:
public static MvcHtmlString RenderLabelFor<TModel, TValue> ( this HtmlHelper html, Expression<Func<TModel, TValue>> value, object htmlAttributes ) where TModel : class { TagBuilder builder = new TagBuilder("td"); builder.MergeAttributes(new RouteValueDictionary(attributes));
However, I get an error on the LabelFor line:
Type arguments to the method "System.Web.Mvc.Html.LabelExtensions.LabelFor (System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)" cannot be taken out of use. Try explicitly specifying type arguments.
Can anyone throw me a bone on this?
source share