ciao
ho scoperto da poco MVC e sto facendo la prima interrogazione su DB
MODEL:
Public Class Agenti
Private m_codage As String
Public Property codage() As String
Get
Return m_codage
End Get
Set(ByVal value As String)
m_codage = value
End Set
End Property
Private m_nome As String
Public Property nomeage() As String
Get
Return m_nome
End Get
Set(ByVal value As String)
m_nome = value
End Set
End Property
End Class
CONTROLLER:
Public Function Agenti() As ActionResult
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
Dim cmdString As String = " SELECT Codage,Nome FROM tabella"
conn = New SqlConnection("...")
cmd = New SqlCommand(cmdString, conn)
Try
conn.Open()
Catch ex As SqlException
Response.Write(ex.Message)
End Try
Dim rdr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim model = New List(Of Agenti)()
While rdr.Read()
Dim age = New Agenti()
age.codage = rdr("Codage")
age.nomeage = rdr("Nome")
model.Add(age)
End While
Return View(model)
End Function
VIEW:
<table>
<tr>
<th>Agenti</th>
<th>
codice
</th>
<th>
agente
</th>
</tr>
<% For Each item In Model%>
<tr>
<td>
@item.agenti.codage
</td>
<td>
@item.agenti.nomeage
</td>
</tr>
<% Next%>
</table>
il reader funziona bene perchè mi restituisce un numero di righe corretto ma la view non mi restituisce i valori dei campi...
sono all'inizio ed ancora debbo capire bene lo switch...help