私はASP.NET MVC2のWebサイトで作業しています。学習のために。私はVisual Basic言語で作業しています。ビューでカスタムASP.NET MVC2 HtmlHelper:渡されたオブジェクトのインスタンスを取得するには?
私はこれやりたい:
Imports System.Runtime.CompilerServices
Imports System.Linq.Expressions
Imports System.Reflection
Public Module HtmlHelpers
<Extension()> _
Public Function EditorForEnumeracion(Of TModel, TValue)(ByVal html As HtmlHelper(Of TModel), ByVal expression As Expression(Of Func(Of TModel, TValue))) As MvcHtmlString
'My stuff goes here
End Function
End Module
問題は、私はインスタンスを取得する方法がわからないということです。だから、
<%: Html.EditorForEnumeracion(Function(v) v.combustible%>
を、私はHtmlHelperの拡張メソッドを作成しました私がヘルパーに渡すv.combustibleオブジェクトの私はvオブジェクトを気にしない。私はvオブジェクトの可燃属性で作業する必要があります。
Hereとhereこれはどうやっているようですがわかりません。また、私はC#ではなくVisual Basicで作業します。
私は式パラメータを使ってEnumeracionオブジェクトのインスタンスを取得できると思いますが、どのように理解できません。
詳細情報
これが私の "Vehiculo" クラスです:
Namespace Models.Automovil
Public Class Vehiculo
Public Property tipo As New Models.Enumeracion("TipoDeVehiculo")
Public Property marca As String
Public Property modelo As String
Public Property numeroDePuertas As Integer
Public Property combustible As New Models.Enumeracion("TipoDeCombustible")
Public Property potencia As Integer
Public Property fechaPrimeraMatriculacion As DateTime
Public Property version As String
Public Property precio As Decimal
Public Property descripcion As String
End Class
End Namespace
そして、これは私の "Enumeracion" クラスです:
Namespace Models
Public Class Enumeracion
Private bd As New tarificadorasegasaEntities
Private diccionario As New Dictionary(Of String, Integer)
Private _nombre As String
Private _clave As String
Private _valor As Integer
Public ReadOnly Property nombre As String
Get
Return _nombre
End Get
End Property
Public ReadOnly Property clave As String
Get
Return _clave
End Get
End Property
Public ReadOnly Property valor As Integer
Get
Return _valor
End Get
End Property
'More stuff here. Methods.
End Class
End Namespace
モデルはVehiculoクラスです。
まだ解決していません。
ありがとうございます。
res.ModelはNothingなので、eもNothingです。 – Daniel
@Daniel、res.ModelがNothingの場合は、ビューが強く型付けされていないか、コントローラアクションからモデルを渡していないことを意味します。 –
あなたは正しいです。どうもありがとうございました。 – Daniel