views:

299

answers:

3

I can't figure out what I'm missing in the following code. I've got a method that should add a (dummy) helper extension:

Imports System.Runtime.CompilerServices

Namespace HtmlHelpers

    Public Module HelpExtensions

        <Extension()> _
        Public Function HelpMe(ByVal HtmlHelper As HtmlHelper) As String
            Return "<a>HELP</a>"
        End Function

    End Module

End Namespace

My view looks like this:

<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="HtmlHelpers" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="body" runat="server">
    <%=Html.HelpMe()%>
</asp:Content>

But this gives me the following error:

'HelpMe' is not a member of 'System.Web.Mvc.HtmlHelper'.

What am I doing wrong?

A: 

Have you tried rebuilding your solution before attempting to use the extension method? I've had to do that with VB.NET in order for the compiler to pick up the existence of my extension methods.

Dennis Palmer
A: 

Not sure why the Import Namespace directive wasn't doing the trick, but I added

<add namespace="MyProject.HtmlHelpers"/>

to the <namespaces> section of web.config and it's working now. Maybe if I had done

<%@ Import Namespace="MyProject.HtmlHelpers" %>

it would have worked as well?

gfrizzle
A: 

I encountered this problem because I hadn't declared the Module to be Public.

This question also asked here

Steven Hines