开发者

Problem creating extension method for HTMLHelper ('TextBoxFor' is not a member of 'System.Web.Mvc.HtmlHelper(Of TModel)')

开发者 https://www.devze.com 2023-03-12 16:14 出处:网络
I have the following extension method that I\'ve built and have working for one MVC3 project, but when trying to use it in another, the compiler (not the view) gives me the error;

I have the following extension method that I've built and have working for one MVC3 project, but when trying to use it in another, the compiler (not the view) gives me the error;

Error   1   'TextBoxFor' is not a member of 'System.Web.Mvc.HtmlHelper(Of TModel)'...

Intellisense shows none of these html element shorcut methods.

I'm sure it's just because I'm missing a reference or something, but beats me what it is.

FImports System.Runtime.CompilerServices

Public Module HtmlHelperExtension

<Extension()> _
Public Function WatermarkedTextBoxFor(Of TModel, TProperty)(ByVal htmlHelper As System.Web.Mvc.HtmlHelper(Of TModel), ByVal expression开发者_StackOverflow中文版 As Linq.Expressions.Expression(Of Func(Of TModel, TProperty)), ByVal htmlAttributes As IDictionary(Of String, Object)) As MvcHtmlString

    Dim propertyMetaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData)

    Return htmlHelper.TextBoxFor(expression, New RouteValueDictionary(htmlAttributes) From {
                                 {"class", "jq_watermark"},
                                 {"title", If(Not String.IsNullOrEmpty(propertyMetaData.Watermark), propertyMetaData.Watermark, propertyMetaData.GetDisplayName())}
                             })

End Function
End Module


I needed to import the System.Web.Mvc.Html namespace

0

精彩评论

暂无评论...
验证码 换一张
取 消