无法建立在VB MVC应用程序的HtmlHelper方法 [英] Can't create HtmlHelper methods in VB MVC app

查看:173
本文介绍了无法建立在VB MVC应用程序的HtmlHelper方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不出什么我缺少在以下code。我有一个应该添加一个(虚拟)辅助扩展的方法:

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?

推荐答案

不知道为什么导入namespace指令没有这样做的伎俩,但我加了

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

<add namespace="MyProject.HtmlHelpers"/>

&LT;&命名空间GT; web.config中的部分,它的工作现在。也许,如果我做了

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

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

这会工作呢?

这篇关于无法建立在VB MVC应用程序的HtmlHelper方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆