Here is my static class:
using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using System.Linq.Expressions; using System.Text; using System.Web; namespace Foo.WebUI.Infrastructure { public static class HtmlHelpers { public static MvcHtmlString Image(this HtmlHelper helper, string src, string altText) { var builder = new TagBuilder("img"); builder.MergeAttribute("src", src); builder.MergeAttribute("alt", altText); return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing)); } public static MvcHtmlString RadioButtonForEnum<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression) { var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); var names = Enum.GetNames(metaData.ModelType); var sb = new StringBuilder(); foreach (var name in names) { var id = string.Format( "{0}_{1}_{2}", htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix, metaData.PropertyName, name );
When I compile this, I get this error:
'System.Web.Mvc.HtmlHelper' does not contain a definition for "RadioButtonFor" and no extension method "RadioButtonFor" that takes the first argument of the type "System.Web.Mvc.HtmlHelper" may be (do you miss the using directive or assembly references?
I got this helper method from this answer:
pass enum to html.radiobuttonfor MVC3
Only Bolivian Here
source share