Remplacer une clé étrangère par la valeur correspondant dans la table où elle est clé primaire
Bonjour.
Je suis développeur web expérimenté mais nouveau dans l'architecture MVC
J'ai une table "Utilisateurs" et "Directions" dont les modèles sont
UtilisateurModele:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Imports System.Data.Entity
Public Class Utilisateur
Public Property Id As Integer
Public Property DirectionId As Integer
Public Property Departement As String
Public Property Service As String
Public Property Matricule As String
Public Property Nom As String
Public Property Prenom As String
Public Property Poste As String
Public Property Tel As String
Public Property Email As String
Public ReadOnly Property FullName As String
Get
Return Nom & " " + Prenom
End Get
End Property
End Class |
DirectionModele:
Code:
1 2 3 4 5 6
| Imports System.Data.Entity
Public Class Direction
Public Property Id As Integer
Public Property Valeur As String
Public Property Supprime As Boolean
End Class |
ClassGnl:
Code:
1 2 3 4 5 6
| Imports System.Data.Entity
Public Class HI_CNX
Inherits DbContext
Public Property Utilisateurs() As DbSet(Of Utilisateur)
Public Property Directions() As DbSet(Of Direction)
End Class |
Dans le controller, j'ai
UtilisateursController:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| @ModelType IEnumerable(Of ANNUAIRE.Utilisateur)
@Code
ViewData("Title") = "Index"
Layout = "~/Views/Shared/_Layout.vbhtml"
End Code
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@*@Html.DisplayNameFor(Function(model) model.FullName)*@
Nom et prénom(s)
</th>
<th>
@*@Html.DisplayNameFor(Function(model) model.DirectionId)*@
Direction
</th>
<th>
@*@Html.DisplayNameFor(Function(model) model.Poste)*@
Poste
</th>
<th>
@*@Html.DisplayNameFor(Function(model) model.Tel)*@
Tél.
</th>
<th>
@*@Html.DisplayNameFor(Function(model) model.Email)*@
Email
</th>
<th></th>
</tr>
@For Each item In Model
@<tr>
<td>
@Html.DisplayFor(Function(modelItem) item.FullName)
</td>
<td>
@Html.DisplayFor(Function(modelItem) item.DirectionId)
</td>
<td>
@Html.DisplayFor(Function(modelItem) item.Poste)
</td>
<td>
@Html.DisplayFor(Function(modelItem) item.Tel)
</td>
<td>
@Html.DisplayFor(Function(modelItem) item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", New With {.id = item.Id}) |
@*@Html.ActionLink("Details", "Details", New With {.id = item.Id}) |*@
@Html.ActionLink("Delete", "Delete", New With {.id = item.Id})
</td>
</tr>
Next
</table> |
Ma préoccupation est de remplacer
Citation:
Envoyé par CSHTML
@Html.DisplayFor(Function(modelItem) item.DirectionId)
par la valeur de la direction correspondant à la "DirectionId"
Merci d'avance