简体   繁体   English

VB.net中的ASP.net MVC HtmlHelper

[英]ASP.net MVC HtmlHelper in VB.net

stupid question here. 愚蠢的问题在这里。 I'm trying to create a helper method, something similar to the radio button list in the MVC futures project (as a learning tool). 我正在尝试创建一个辅助方法,类似于MVC期货项目中的单选按钮列表(作为一种学习工具)。

I'm trying to convert the C# code: 我正在尝试转换C#代码:

 public static string[] RadioButtonList(this HtmlHelper htmlHelper, string name, IDictionary<string, object> htmlAttributes) {

to a method signature in VB.net, but I'm not sure how to write the first parameter in VB.net, or what you would call this, so I could look it up? 到VB.net中的方法签名,但是我不确定如何在VB.net中编写第一个参数,或者您将如何称呼它,所以我可以查找它?

I'm not either. 我也不是。 But this is the signature of an extension method. 但这是扩展方法的签名。 Here's the MSDN docs on doing this in VB. 这是有关在VB中执行此操作的MSDN文档

I believe this will work as long as you remember to mark it as an extension method, you could look up Extension Methods on MSDN.com . 我相信,只要您记得将其标记为扩展方法,便可以使用,您可以在MSDN.com上查找扩展方法。 They have examples of how to write extension methods in VB.net. 他们有如何在VB.net中编写扩展方法的示例。

<System.Runtime.CompilerServices.Extension> _
Public Shared Function RadioButtonList(ByVal htmlHelper As HtmlHelper, ByVal name As String, ByVal htmlAttributes As IDictionary(Of String, Object)) As String()
    
End Function

They are called Extension methods , and are declared in VB.Net like this: 它们被称为扩展方法 ,并在VB.Net中这样声明:

<System.Runtime.CompilerServices.Extension()> _
Public Sub RadioButtonList(ByVal name As String, ...)
// There's no "this" parameter at all...

Extension methods in VB can only be declared from within a module, not a class, so a complete skeleton definition would look something like this... VB中的扩展方法只能在模块中声明,而不能在类中声明,因此完整的框架定义应如下所示:

Imports System.Web.Mvc

Public Module MyModule

    <System.Runtime.CompilerServices.Extension> _
    Public Function MyHelper (ByVal helper As HtmlHelper, MyParameter as String) As String

    End Function

End Module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM