Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何在自定义HtmlHelper扩展上修复intellisense?_Vb.net_Visual Studio 2010_Razor_Intellisense_Html Helper - Fatal编程技术网

Vb.net 如何在自定义HtmlHelper扩展上修复intellisense?

Vb.net 如何在自定义HtmlHelper扩展上修复intellisense?,vb.net,visual-studio-2010,razor,intellisense,html-helper,Vb.net,Visual Studio 2010,Razor,Intellisense,Html Helper,结合MVC3和Razor使用VB.NET 我有一个测试页面,用于自定义扩展到htmlhelper。Visual Studio告诉我视图不正常: index.vbhtml的代码(视图) @ViewData(“消息”) @Html.CustomLink(“文本321312”,123) 错误:CustomLink不是System.Web.Mvc.HtmlHelper(..)的成员 LinkExtension.vb的代码(扩展名) 导入System.Runtime.CompilerServices 导

结合MVC3和Razor使用VB.NET

我有一个测试页面,用于自定义扩展到htmlhelper。Visual Studio告诉我视图不正常:

index.vbhtml的代码(视图)
@ViewData(“消息”)
@Html.CustomLink(“文本321312”,123)
错误:CustomLink不是System.Web.Mvc.HtmlHelper(..)的成员

LinkExtension.vb的代码(扩展名)
导入System.Runtime.CompilerServices
导入System.Web.Mvc
公共模块htmlHelperExtensions
_
公共函数CustomLink(htmlHelper为htmlHelper,linkText为String,uuid为Short)为MvcHtmlString
返回MvcHtmlString.Create(String.Format(“”,linkText,uuid)
端函数
端模块
web.config(添加了名称空间) 我在general web.config和view web.config中都添加了对我的库的引用
(我还尝试将其添加到控制器。)


[...]

页面正确运行并根据我的需要构建html。但是VS不断告诉我代码不正确(CustomLink不是“System.Web.HtmlHelper(of Object)”的成员)!有什么想法吗?

在添加命名空间时尝试指定项目:

<add namespace="MyProject.linkExtension" />

如果这没有帮助,那么您运行的是哪个版本的MVC?A由同样使用VB.NET的人提供。在这种情况下,他们在将所有项目升级到MVC 3或卸载MVC 3(因为他们使用的是MVC 2)时使其正常工作。显然,安装SP1和Azure工具时也会受到一些干扰。

有时在添加之后如果将名称空间添加到视图文件夹中的web.config文件中,则需要卸载项目,然后重新加载该项目以获取新帮助程序类的Intellisense。我将名称空间添加到视图文件夹中的web.config中,但仍然会出现相同的错误。LinkedExtension是我的根项目名称,这就是为什么没有定义名称空间。LinkedExtension.linkExtension有点多余。我尝试添加了一个名称空间:没有更改任何东西(仍然有效,仍然告诉它不正确)。该项目基于,即MVC3(需要/使用Razor)。不确定SP1(已安装)和Azure工具(未安装)。嗯,似乎我的库使用的是MVC2 dll,而不是MVC3 dll。现在,它工作得很好。
Imports System.Runtime.CompilerServices
Imports System.Web.Mvc

Public Module htmlHelperExtensions
    <Extension()> _
    Public Function CustomLink(htmlHelper As HtmlHelper, linkText As String, uuid As Short) As MvcHtmlString
        Return MvcHtmlString.Create(String.Format("<a href="#{1}">{0}</a>", linkText, uuid )
    End Function
End Module
<system.web>
  <pages>
    <namespaces>
      [...]
      <add namespace="linkExtension" />
    </namespaces>
  </pages>
</system.web>
<add namespace="MyProject.linkExtension" />
Namespace linkExtension
    Public Module htmlHelperExtensions
        <Extension()> _
        Public Function CustomLink(htmlHelper As HtmlHelper, linkText As String, uuid As Short) As MvcHtmlString
            Return MvcHtmlString.Create(String.Format("<a href="#{1}">{0}</a>", linkText, uuid )
        End Function
    End Module
End Namespace